Skip to main content
Known Participant
May 22, 2013
Answered

More concise script?

  • May 22, 2013
  • 4 replies
  • 637 views

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.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

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.


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{

}

4 replies

kglad
Community Expert
Community Expert
May 22, 2013

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?

CuwenAuthor
Known Participant
May 22, 2013

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.

CuwenAuthor
Known Participant
May 22, 2013

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.