okay, I have an accordian menu that basically loads in the butons with text,...NO content yet. I am now telling the duplicated movie clip to play a frame within that movieclip. I now want to load another xml file, to produce the content of this because I am setting up animations within the duplicated movie clip. I can get the xml file items to get into their variables, but the movie clip within the movie clip that is supposed to load all of this content is not showing up. Hope you can help.
code on in root of file
//import tweenlite classes
import gs.TweenLite;
import gs.globals;
import gs.easing.*;
var masker;
var MENU_ARRAY:Array; //used to save the items data
var OPENED_MENU:int; //to inform the menu that should be open at startup
var MOVE_ON_MOUSE_OVER:Boolean=false; //tha name says everything
var xmlLoader:URLLoader; //the xml loader
loadXML("menu2.xml"); //load the xml
function loadXML(Uri:String):void {
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onComplete);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
xmlLoader.load(new URLRequest(Uri));
}
function onError(evt:ErrorEvent):void {
trace("cannot load xml file");
}
function onComplete(evt:Event):void {
//read and load xml into array, by parsing it using prepareMenu
MENU_ARRAY=prepareMenu(xmlLoader.data.toString());
placeItemsOnStage(); //place all required items on stage.
}
function placeItemsOnStage():void {
var pos:Number=0;
var labelStyle:TextFormat;
var mytext:String = '';
//define the container properties
menuContainer.x=0;
menuContainer.y=0;
for(var c:int=0; c<MENU_ARRAY.length; c++) {
var it:menuItem = new menuItem; //load out menuItem, because its exported to AS, we can use it here
it.x=c*30; //its the gray border width
it.y=0; //place on top
it.id="Item-"+c; //id the menuItem
it.name="Item-"+c; //name de menuItem
it.posX=pos; //actual pos, useful to open and know is position
it.itemLabel.text=String(MENU_ARRAY[c].Ititle).toUpperCase(); //load the label in uppercase
mytext = it.itemLabel.text;
var a:String = mytext;
var aa:int = mytext.length;
var b:String = '';
var e:int = 0;
var d:int = 1;
var f:String = '';
for (var i:int=0; i<aa; i++)
{
if (i == 0)
{
b = a.substr(e,1) + "\n";
}
else
{
b = b + a.substr(e,1) + "\n";
}
e = e + 1;
d = d + 1;
}
it.itemLabel.text = b;
labelStyle= new TextFormat();
labelStyle.color = MENU_ARRAY[c].Icolor; //this must be an hexadecimal color: 0xffcc00
labelStyle.bold = true; //this must be an hexadecimal color: 0xffcc00
it.itemLabel.setTextFormat(labelStyle); //apply the textFormat.
it.tweenmc.stop();
it.addEventListener(MouseEvent.CLICK, onMouseClick); //add mouse click listener
if(MOVE_ON_MOUSE_OVER==true) it.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); //if configured, load the mouse over event
it.useHandCursor=true; //use hand cursor
it.buttonMode=true; //buttonMode
it.itemText.visible=false; //hide the textField
menuContainer.addChild(it); //add the menu item as child
//if(String(MENU_ARRAY[c].IcontentType)=="image/swf") { //check the content and load things accordint to it
// var ldr:Loader = new Loader();
// ldr.x=30;
// ldr.y=0;
// it.addChild(ldr);
// ldr.load(new URLRequest(MENU_ARRAY[c].IcontentData.toString()));
//}
// else if(String(MENU_ARRAY[c].IcontentType)=="text") {
// it.itemText.visible=true;
// it.itemText.text=MENU_ARRAY[c].IcontentData.toString();
// }
pos+=28; //the next menuItem x position
}
//put mask in place
masker.width=(MENU_ARRAY.length*29+800)
masker.height=menuContainer.height;
masker.x=0;
masker.y=0;
moveItem(OPENED_MENU-0); //open menu confirured in XML
}
function onMouseOver(evt:MouseEvent):void {
if(evt.target.name.toString()=="buttonBack") prepareMove(evt)
if(evt.target.name.toString()=="tweenmc") prepareMove(evt)
}
function prepareMove(evt:MouseEvent):void {
var targetName:String = evt.currentTarget.name.toString(); //get the menuItem
var temp:Array = targetName.split("-"); //split his name: Item-x
trace(temp)
var itemNumber:int=(temp[1]); //got item number
moveItem(itemNumber); //move it
}
function onMouseClick(evt:MouseEvent):void {
if(evt.target.name.toString()=="buttonBack") prepareMove(evt); //mouse action was done in buttonBack
//else trace("Item "+evt.currentTarget.name+" clicked!"); //mouse action was made on accordion area
//this.tweenmc.gotoAndPlay(2)
//evt.target.name.tweenmc.gotoAndPlay(2); //trace(evt.target.name.toString());
//mouse action was done in buttonBack
//(evt.target as menuItem).tweenmc.gotoAndPlay(2);
//(evt.target as menuItem).tweenmc.gotoAndStop(2);
else
{
globals.num.foo = 2;
trace(globals.num.foo);
//(evt.currentTarget as menuItem).tweenmc.gotoAndPlay(2);
trace("Item "+evt.currentTarget.name+" clicked!");
} //trace("Item "+evt.currentTarget.name+" clicked!"); //mouse action was made on accordion area
}
function moveItem(num:int):void {
var itemToMove:menuItem=menuContainer.getChildByName("Item-"+String(num)) as menuItem;
itemToMove.tweenmc.gotoAndPlay(2);
itemToMove.gotoAndPlay(2);
//get the menuItem child
for(var m=0;m<MENU_ARRAY.length;m++) //move one-by-one to the new position
{
var tempMc = menuContainer.getChildByName("Item-"+m);
if(tempMc.x > itemToMove.x) TweenLite.to(tempMc, 1, {x:((tempMc.posX) + itemToMove.width-30), ease:Quart.easeOut}); //see tweenLite for info about this.
else if(tempMc.x <= itemToMove.x) TweenLite.to(tempMc, 1, {x:(tempMc.posX), ease:Quart.easeOut});
}
}
function prepareMenu (XMLData:String):Array
{
//make sure it cames in XML
var menuXML:XML = new XML(XMLData);
//just in case
menuXML.ignoreWhitespace = true;
//get XML item's entrys
var XMLItems = menuXML.descendants("item");
//load all items into an array
var itemsArray:Array = new Array();
var itemObj:Object;
for(var i in XMLItems)
{
itemObj=new Object();
itemObj.Ititle=XMLItems[i].@Ititle;
itemObj.IcontentType=XMLItems[i].@IcontentType;
itemObj.IcontentData=XMLItems[i].@IcontentData;
itemObj.Icolor=XMLItems[i].@Icolor;
itemObj.itemID="menu"+i;
itemsArray.push(itemObj);
}
OPENED_MENU=menuXML.@menuOpen; //get menu for open.
MOVE_ON_MOUSE_OVER=(menuXML.@moveOnMouseOver.toString()=="true" ? true : false); //get the option for load or not mouseOver open
return itemsArray;
}
//finish.
stop();
code on root of duplicated movie clip that was created above.
stop();
var xmlLoader2:URLLoader; //the xml loader
var MENU_ARRAY2:Array; //used to save the items data
var OPENED_MENU2:int; //to inform the menu that should be open at startup
var MOVE_ON_MOUSE_OVER2:Boolean=false; //tha name says everything
loadXML("in_menu.xml"); //load the xml
function loadXML(Uri:String):void {
xmlLoader2 = new URLLoader();
xmlLoader2.addEventListener(Event.COMPLETE, onComplete2);
xmlLoader2.addEventListener(IOErrorEvent.IO_ERROR, onError2);
xmlLoader2.load(new URLRequest(Uri));
}
function onError2(evt:ErrorEvent):void {
trace("cannot load xml file");
}
function onComplete2(evt2:Event):void {
//read and load xml into array, by parsing it using prepareMenu
MENU_ARRAY2=prepareMenu2(xmlLoader2.data.toString());
placeItemsOnStage2(); //place all required items on stage.
}
function placeItemsOnStage2():void
{
var pos2:Number=0;
var labelStyle2:TextFormat;
for(var c2:int=0; c2<MENU_ARRAY2.length; c2++)
{
var it:menuItem = new menuItem;
var it2:inMenu = new inMenu; //load out menuItem, because its exported to AS, we can use it here
it.it2.x=c2;//*30; //its the gray border width
it.it2.y=0; //place on top
it.it2.id="Item-"+c2; //id the menuItem
it.it2.name="Item-"+c2; //name de menuItem
it.it2.posX2=pos2; //actual pos, useful to open and know is position
it.it2.xmltxt.text=String(MENU_ARRAY2[c2].Ititle).toUpperCase(); //load the label in uppercase
trace(it2.xmltxt.text);
labelStyle2= new TextFormat();
labelStyle2.bold = true; //this must be an hexadecimal color: 0xffcc00
it.it2.xmltxt.setTextFormat(labelStyle2); //apply the textFormat.
trace(it2.xmltxt.text);
it.it2.useHandCursor=true; //use hand cursor
it.it2.buttonMode=true; //buttonMode
var ldr2:Loader = new Loader();
ldr2.x=33;
ldr2.y=0;
it2.addChild(ldr2);
ldr2.load(new URLRequest(MENU_ARRAY2[c2].IcontentData.toString()));
}
pos2+=28;
}
function prepareMenu2 (XMLData2:String):Array
{
//make sure it cames in XML
var menuXML2:XML = new XML(XMLData2);
//just in case
menuXML2.ignoreWhitespace = true;
//get XML item's entrys
var XMLItems2 = menuXML2.descendants("image1");
//load all items into an array
var itemsArray2:Array = new Array();
var itemObj2:Object;
for(var i in XMLItems2)
{
itemObj2=new Object();
itemObj2.Ititle=XMLItems2[i].@Ititle;
trace(itemObj2.Ititle);
//itemObj2.IcontentType=XMLItems2[i].@IcontentType;
itemObj2.IcontentData=XMLItems2[i].@IcontentData;
trace(itemObj2.IcontentData);
//itemObj2.Iimage=XMLItems2[i].@Iimage;
itemObj2.Iurl=XMLItems2[i].@Iurl;
trace(itemObj2.Iurl);
//trace(itemObj2.Iurl);
itemObj2.itemID="menu"+i;
itemsArray2.push(itemObj2);
}
OPENED_MENU2=menuXML2.@menuOpen; //get menu for open.
MOVE_ON_MOUSE_OVER2=(menuXML2.@moveOnMouseOver.toString()=="true" ? true : false); //get the option for load or not mouseOver open
return itemsArray2;
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288:
- stage.jpg
- 233 KB
stage of flash file
- before-click-on-accordian-menu.jpg
- 300 KB
before i click on accordian menu
- on-click-accordion.jpg
- 310 KB
what happens after i click on accordion item
- duplicated-mc-root.jpg
- 282 KB
root of movie clip that gets duplicated





by: blue-geniePosted on 2009-08-22 at 02:19:08ID: 25157997
you should create a class for each of the items then create instances of them in the base class and add them to the stage
var obj:ClassName;
obj:ClassName = new ClassName;
addChild(obj);