Solved

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

Posted on 2011-09-29
3
209 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
  • 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 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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 select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now