I am new to AS3, and my current problem is with placing actions on buttons. I have gotten a basic button working, but the problem comes up when I need to put actions on a button that is on a MovieClip - the problem occurs because the first frame of the movie clip doesn’t have the button in it, it is the second frame that I have the button appear.
Since it is hard for me to explain I have attached an FLA example of my situation.
In the FLA I have a MovieClip which I have given the class “HUDclass” in linkage. I add this MovieClip to the timeline, and then place actions on the button “menuButton” (which is inside the HUDclass movieclip). This button works fine by making the movieclip “menu” toggle between frame 1 and 2, but the problem is I need to add an action to another button, “qualityButton”, on frame 2 of the “menu” movieclip. Where should I add the event listener to this button if it only appears on frame 2 of the movieclip?
This is the code from the main timeline of my FLA.
var hud:HUDclass = new HUDclass;
addChild(hud);
function displayMenu(event:MouseEvent):void{
if(hud.menu.currentFrame == 1){
hud.menu.gotoAndStop(2);
hud.menu.qualityButton.addEventListener(MouseEvent.CLICK,toggleQuality);
}else{
hud.menu.gotoAndStop(1);
}
}
hud.menuButton.addEventListener(MouseEvent.CLICK,displayMenu);
function toggleQuality(event:MouseEvent):void{
if(stage.quality == "high"){
stage.quality = "low";
}else{
stage.quality = "high";
}
}
In this example I have tried adding the event listener when I make the movieclip go to frame 2, which doesn’t work. I have tried a few other things, but I havent been able to get it to work.
What is the best way to do this right? Help would be appriciated