I have a movie clip with five buttons inside that have named instances. Whenever I try to use
stop(); // to stop the playhead at frame 1
power_btn.addEventListener(MouseEvent.CLICK, doClick);
function doClick(e:MouseEvent):void
{
gotoAndPlay(11);
}
flash cannot find the instance inside the movie clip. Do I need to add a path or something to tell flash exactly where to get power_btn from the movieclip?
If your movieclip is on the root, you would use somethinglike this:
_root.movieclip.buttoninside.onRelease=function(){
do stuff
}
that’s the proper path to your movieclip button inside your main movieclip if it’s on the timeline. If you’re still having issues, can you upload yout fla?
//edit…oops…thought this was in the Flash 8 forum…I’m assuming AS3 is different. I’ll move along now
[QUOTE=ShawnMattCraw;2338049]I have a movie clip with five buttons inside that have named instances. Whenever I try to use
stop(); // to stop the playhead at frame 1
power_btn.addEventListener(MouseEvent.CLICK, doClick);
function doClick(e:MouseEvent):void
{
gotoAndPlay(11);
}
flash cannot find the instance inside the movie clip. Do I need to add a path or something to tell flash exactly where to get power_btn from the movieclip?[/QUOTE]
I believe you’ve excluded the movieclip container from the path.
ie: mc_container.power_btn.addEventListener(MouseEvent.CLICK, doClick);
IMO, you should be using frame labels(instead of frame numbers) that correspond to your button instance names.
ie: button instance “btn1” will gotoAndPlay frame label “btn1” and so forth.
example fla that functions this way is attached.
The advantage is that you can rearrange the timeline without breaking your code.
stop();
/*
listener is attached to the movieclip wrapper that contains all of the named buttons.
This listener can serve multiple buttons.
A basic explanation of why this works: AS3 mouse events travel "downward" through the display list until they reach the last named object within the targeted display object container; this becomes the event.target.
In this case, the display list is: stage>buttongroup>btn1
*/
buttonGroup.addEventListener(MouseEvent.CLICK, doClick, false, 0, true);
//enable handcursor for event targets; ignore buttongroup as a target.
buttonGroup.mouseEnabled = false;
buttonGroup.buttonMode = true;
var button:String = "";
function doClick(evt:MouseEvent):void {
button = evt.target.name;//value of button variable = the button instance name.
trace(button);
gotoAndPlay(button);//go to frame label that matches the value of the button variable. stop(); action should be placed each frame label.
}
I got it to work but i ran into another problem. I added a script
stop();
japanese_btn.addEventListener(MouseEvent.CLICK, doClick);
function doClick1(e:MouseEvent):void
{
gotoAndPlay("pee");
}
I have a list of words that come down and they are buttons to click to move to different frames. They are buttons and they work but when I click them they just use the first that brought them up and dont go to the frame label pee