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.