?
Solved

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

Posted on 2011-09-29
3
Medium Priority
?
249 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

The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

801 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