Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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.

726 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