Solved

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

Posted on 2011-09-29
3
226 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

810 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