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

how do I shorten 50 lines of script?

New Here ,
Nov 21, 2008 Nov 21, 2008

Copy link to clipboard

Copied

How can I simplify my script for a page that has tons of buttons?

if I have 50 buttons on a page, is there a way for me to say
button1 thru button50.buttonmode=true???

or do I have to have 50 lines that say
b1.buttonmode=true;
b2.buttonmode=true; ..... and so on?

these buttons all have different functions so I can't just have them all be Instances of the same object without different instance names.
TOPICS
ActionScript

Views

759
Translate

Report

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
Guru ,
Nov 21, 2008 Nov 21, 2008

Copy link to clipboard

Copied

add them to an array.

var btnAr:Array = new Array(btn1, btn2, btn3);
for(var bt:uint = 0;bt<btnAr.length;bt++){
btnAr[bt].buttonMode = true;
};

Votes

Translate

Report

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
LEGEND ,
Nov 21, 2008 Nov 21, 2008

Copy link to clipboard

Copied

If they are stage instances (not dynamic) and the number of them is known and fixed (say 50), you can skip the array and just loop thru...

for(var i:uint =1; i<51; i++){
this["b"+String(i)].buttonMode = true;
};

Votes

Translate

Report

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
New Here ,
Nov 22, 2008 Nov 22, 2008

Copy link to clipboard

Copied

LATEST
quote:

Originally posted by: NedWebs
If they are stage instances (not dynamic) and the number of them is known and fixed (say 50), you can skip the array and just loop thru...

for(var i:uint =1; i<51; i++){
this["b"+String(i)].buttonMode = true;
};



that's right

Votes

Translate

Report

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
Participant ,
Nov 22, 2008 Nov 22, 2008

Copy link to clipboard

Copied

I think if you are using a buttons they would not need to be set as buttonmode=true, but as I see you are using movieclips as buttons, is that right?

thanks NedWebs I might need this code too in the future.

thanks everybody

Votes

Translate

Report

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 ,
Nov 22, 2008 Nov 22, 2008

Copy link to clipboard

Copied

You could also put this in the first frame of the button movie clip then all its instances will be buttonMode true:

stop();
buttonMode=true;

Votes

Translate

Report

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