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

More efficient code

Participant ,
Oct 28, 2012 Oct 28, 2012

Copy link to clipboard

Copied

Can this code be made shorter or leaner?

a_btn.useHandCursor = true;

b_btn.useHandCursor = true;

c_btn.useHandCursor = true;

d_btn.useHandCursor = true;

e_btn.useHandCursor = true;

f_btn.useHandCursor = true;

g_btn.useHandCursor = true;

h_btn.useHandCursor = true;

i_btn.useHandCursor = true;

j_btn.useHandCursor = true;

k_btn.useHandCursor = true;

l_btn.useHandCursor = true;

Thanks

TOPICS
ActionScript

Views

814

Translate

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

correct answers 1 Correct answer

LEGEND , Oct 28, 2012 Oct 28, 2012

for(var i:uint=0; i<btns.length; i++){

    btns.useHandCursor = true;

}

Votes

Translate

Translate
LEGEND ,
Oct 28, 2012 Oct 28, 2012

Copy link to clipboard

Copied

Because you are using letters rather than numbers it becomes a little less able to be done efficiently as far as the amount of code needed goes.

One way would be to just put the instance names in an array and loop thru the array to assign the property.

   btns[#].useHandCursor = true; // where # is the loop increment

Another could be to just have the unique letter elements of the button instance names in an array and use bracket notation to target the buttons to assign the properties.

   this[letters[#]+"_btn"].useHandCursor = true;  // same deal with #

Votes

Translate

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 ,
Oct 28, 2012 Oct 28, 2012

Copy link to clipboard

Copied

Hello Ned. Thank you.

What type of loop? Can you provide a sample?

Thanks

Votes

Translate

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 ,
Oct 28, 2012 Oct 28, 2012

Copy link to clipboard

Copied

for(var i:uint=0; i<btns.length; i++){

    btns.useHandCursor = true;

}

Votes

Translate

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 ,
Oct 28, 2012 Oct 28, 2012

Copy link to clipboard

Copied

Thanks Ned!!!

Votes

Translate

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 ,
Oct 29, 2012 Oct 29, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

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