Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-02-2012, 06:35 PM   #1
Registered User
Join Date: Jul 2010
Posts: 1
Default Playing a MC defined by XML


Last edited by activeradio; 07-02-2012 at 08:48 PM.
activeradio is offline   Reply With Quote
Old 07-02-2012, 10:10 PM   #2
Senior Member
[afz]snickelfitz's Avatar
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,408

ActionScript Code:
package {     import flash.display.*;     import flash.events.*;     import flash.text.*;         public class Main extends MovieClip     {         // MovieClips on the stage assigned to buttons         public var home:MovieClip;         public var about:MovieClip;         public var contact:MovieClip;         //substitute internal XML for this example         private var xml:XML;         // container for the buttons         private var buttons:Sprite;         // track previous and current buttons         private var currentButton:MovieClip;         private var previousButton:MovieClip;                 public function Main()         {             xml =             <site>                 <item title="Home" clip="home"/>                 <item title="About" clip="about"/>                 <item title="Contact" clip="contact"/>             </site>                         buttons = new Sprite();             addChild(buttons);                         for each(var t in xml..item)             {                 var b:Btn = new Btn();                 b.buttonLabel.autoSize = TextFieldAutoSize.LEFT;                 b.buttonLabel.text = t.@title;                 // assign a clip to the button using a dynamic property                 b.clip = this[t.@clip] as MovieClip;                 b.buttonMode = true;                 b.mouseChildren = false;                 b.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);                                 b.x = buttons.width;                 buttons.addChild(b);             }         }                 private function onClick(e:MouseEvent):void         {             currentButton = e.target as MovieClip;             currentButton.clip.play();                         if(previousButton)             {                 previousButton.clip.gotoAndStop(1);             }                         previousButton = currentButton;         }     } }

Edit: noticed that you solved this problem.
Post your solution for future queries.
[afz]snickelfitz is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:21 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.