//set up xml objects var xmlLoader:URLLoader = new URLLoader(); var xmlData:XML; var accItem:XMLList; var subItem:XMLList; var accLoader:Loader; //var current_Id:String = ""; xmlLoader.addEventListener(Event.COMPLETE, LoadXML); xmlLoader.load(new URLRequest("accordion.xml")); function LoadXML(e:Event):void { trace("loading XML"); xmlData = new XML(e.target.data); accItem = new XMLList(xmlData.menu.attributes()); var maxItems:int = accItem.length(); var maxSubItems:int = new int; trace("Total Amount of primary menu items = "+maxItems); //var slider:Slidebar; // Slider X //var maxSubItems:int = 4; // number of sub buttons var dist = 4; // distance in pixels between items var sDist = 1; //distance in pixels between sub items var speed = 10; // speed of animation var itemArray:Array = new Array(); // hold reference to all clips var growingTimer:Number = 0; // hold reference to growing anim timer var reducingTimer:Number = 0; // hold reference to reducing anim timer var growingVal:Object = null; // hold reference to growing object var reducingVal:Object = null; // hold reference to reducing object function init(){ // loop and create top buttons (primary) for(var i:uint=0;i<=maxItems; i++){ // create clip var topClip = createTopClip(i); //add the text //topClip.topText.text = accItem[i]; // add to array itemArray.push(topClip) // show hand cursor topClip.buttonMode = true; // delegate onclick event topClip.addEventListener(MouseEvent.CLICK,onClickHandler); // add to stage addChild(topClip); subItem = new XMLList(xmlData.menu.item.(attributes() == accItem[i])); trace("------------"); maxSubItems = subItem.length(); trace(maxSubItems); } // set default reference to first clip as growing Item setGrowing(itemArray[0]); // set default reducingItem clip reference setReducing(itemArray[1]); // listen to enterFrame event addEventListener(Event.ENTER_FRAME, renderHandler); // create slider //createSlider(); } // Create a button clip sets properties and adds sub clips function createTopClip(i:uint):MovieClip{ // Create Primary Button var clip:PrimaryButton= new PrimaryButton(); // set properties clip.x= (stage.stageWidth-clip.width)/2; clip.y= 10+(i*(clip.height+dist)); // set original height for clip (to animate later) clip.h = clip.height; // Create and Add mask covering all subItems created clip.maskSprite = createMask(clip.width,clip.height); // add Mask on top clip.addChild(clip.maskSprite); // add mask to clip clip.mask = clip.maskSprite; // loop and create Sub Buttons for(var j:uint=1;j<=maxSubItems+1; j++){ // create Sub Item objects from library var subClip:SecondaryButton= new SecondaryButton(); // set properties subClip.x= 0; subClip.y= j*(subClip.height+sDist); // add to stage clip.addChild(subClip); } // set target height for clip (to animate later) clip.dh = subClip.y; // target height //return instance reference return clip; } // render grow//shrink animation function renderHandler(event:Event):void{ // animate clip growing using sin equiation growingVal.maskSprite.height = animateSin(growingVal.maskSprite.height,growingVal.dh,true); // animate clip reducing using sin equiation reducingVal.maskSprite.height = animateSin(reducingVal.maskSprite.height,reducingVal.h,false); // make next clip position reflect previous clips for (var i:uint=0;i