Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do MyObject[IntA]._blah?

Status
Not open for further replies.

DraconicArchmage

Programmer
Jan 19, 2002
3
US
I'm stuck. Yes, you probably already knew that, but this is my last resort.
I'm making a program that has several sprites move and colide using vecotrs and physics and such, and I'm doing it in flash, as it will be part of a website. I'm relatively new to flash, but not new to programming. However, it seems "ActionScript" is very confusing and hard to use.
The question I am asking is how do I create an array of objects? I have nearly everything I need, but I need to be able to create another instance of that object via code, and control it via code. So far, I have objects of "obj01", named "obj01", "obj02", "obj03" and "obj04". I did this very similarly to the Flash 5 sample "Circular motion".
Now, I need to be able to refer to the objects through code, so I don't have to copy and paste and replace numbers. The way this is usually done is an array. How do I get from typing
obj01._blah = Blah
obj02._blah = Blah
to
for(IntA = 1; IntA <= ObjectCount; IntA++){
obj[IntA]._blah = Blah
}
?
I really need to do this, and to be able to create more objects later on. Any help or advice is greatly appreciated, and I will give credit to those who actually have helped quite a bit. In case the e-mail notification bit doesn't work, my e-mail is brian@embergamedev.f2s.com . Thank you for your time and patience.

P.S. Mind that I'm still fairly new, so the more explaination on what things are and do, the better.
 
The best way to do this in Flash is to use duplicateMovieClip() inasmuch as all clips are self-contained objects anyway.

Creating new clips is easy, as is addressing them dynamically with array notation.


//creation of clips
for(i=1;i<10;i++){
duplicateMovieClip(_root.seedClip,&quot;copyClip&quot;+i,i);
//addressing clips and setting properties
_root[&quot;copyClip&quot;+i]._x=Math.random()*500;
_root[&quot;copyClip&quot;+i]._y=Math.random()*400;
}



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top