Copy link to clipboard
Copied
Is there a way I can shorten this script so that I don't have to copy and paste it for each button?:
myContent(scrollPane.content).RetClip_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_SealInstaller);
function fl_ClickToGoToAndStopAtFrame_SealInstaller(event:MouseEvent):void
{
gotoAndStop("SealInstaller");
}
It seems like it would be pretty lengthy and messy of me just to copy and paste that same code for each of my 21 buttons. Now, I don't want to load them as an array. That's not my goal, but I was hoping there was another way to combine the script for all the buttons or just shorten it up.
I hope I'm making sense.
if every object inside that movieclip is one of your buttons, you can use something like:
for(var i:int=0;i<yourmovieclip.numChildren;i++){
SimpleButton(yourmovieclip.getChildAt(i)).addEventListener(MouseEvent.CLICK,f);
}
function f(e:MouseEvent):void{
}
Copy link to clipboard
Copied
if the buttons are not listed in an array or some other list accessible to actionscript, there has to be some pattern or commonality that can be used to reference your buttons. is there?
Copy link to clipboard
Copied
I hope I answer your question correctly. I just place invisible buttons over image thumbnails that I have mapped out in a movieclip (myContent). The script above just says to go into my movieclip and access the button there. Is there a way I only have to say go into the movieclip once and then list all those buttons there and what I want each one to do (go to and stop at a certain frame label)?
I hope I'm saying this correctly. My terminology and how I'm explaining this is probably horrible.
Copy link to clipboard
Copied
Or maybe it would be better to put all the AS for the buttons inside of the movieclip where the buttons are and just tell each button to go to the root of the file (the stage) and go to a certain frame label? But I don't know if that's proper AS3 coding, if it can even be done, or if it's even recommended. Right now I just have AS in one layer on the stage calling to the movieclip when it's loaded into the scrollpane.
Copy link to clipboard
Copied
if every object inside that movieclip is one of your buttons, you can use something like:
for(var i:int=0;i<yourmovieclip.numChildren;i++){
SimpleButton(yourmovieclip.getChildAt(i)).addEventListener(MouseEvent.CLICK,f);
}
function f(e:MouseEvent):void{
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now