Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

More concise script?

Explorer ,
May 22, 2013 May 22, 2013

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.

TOPICS
ActionScript
586
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 22, 2013 May 22, 2013

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{

}

Translate
Community Expert ,
May 22, 2013 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 22, 2013 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 22, 2013 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2013 May 22, 2013
LATEST

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{

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines