[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to add numbered objects from library to array (Flash AS3)?

Posted on 2011-09-29
3
Medium Priority
?
251 Views
Last Modified: 2012-05-12
Plain and simple. I have 8 Buttons. The linkage class names are bINC1 through bINC8. I want to assign them to an array so I can do stuff with them.

I could maybe go something like:

myArray[1]:bINC1 = new bINC1();
myArray[2]:bINC2 = new bINC2();

But that's pretty tedious.

I can't do this, however, in a for/next loop like this one (after defining "n"):

myArray[1]:bINC1 = new ("bINC" + n)();

because that throws up an error.

This is a foundation for some larger arrays of buttons and MC's and I'd like to find a way to do this....

Any help?
0
Comment
Question by:chevronrod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 36816185
No you don't need to specify a Array item type:)

its so simple

myArray.push(new bINC1());
myArray.push(new bINC2());

That will add your symbols to array if you want to use strong type in the array you must use a Vector class

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html
0
 

Author Comment

by:chevronrod
ID: 36817063
Interesting. But if I have 50 objects it's a chore, even after copying all the lines, to change all the numbers from 1 to 2, 1 to 3, 1 to 4, etc., etc. Can't this be done in a for loop?

I also don't know what "strong type...use a Vector class" means.

And if I just use the code lines you supplied, I get this error:

1120: Access of undefined property myArray.
0
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 36817146
yes
for(var i:uint = 0; i < 10; i++){
    var className:String = flash.utils.getQualifiedClassName("bINC" + (i + 1) ); 
    var cls:Class = flash.utils.getDefinitionByName(className) as Class; 

    myArray[i] = new cls(); //or myArray.push(new cls());
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to how to record live broadcast.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question