Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

looping for different object

Community Beginner ,
Jul 31, 2009 Jul 31, 2009

Lets, say I need to show loop for object with different instance. Is it possible ?

var myObj1:Sprite=new Sprite();

var myObj2:Sprite=new Sprite();

var myObj3:Sprite=new Sprite();

TOPICS
ActionScript
428
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 31, 2009 Jul 31, 2009

I would put the intances in a vector (since you are using the same datatype - Sprite):

var arr:Vector.<Sprite> = new Vector.<Sprite>();

for (var i:uint=0;i<3;i++) {

   arr.push(new Sprite());

}

Then you can also loop back through the array to access the instances.

Translate
Explorer ,
Jul 31, 2009 Jul 31, 2009

I would put the intances in a vector (since you are using the same datatype - Sprite):

var arr:Vector.<Sprite> = new Vector.<Sprite>();

for (var i:uint=0;i<3;i++) {

   arr.push(new Sprite());

}

Then you can also loop back through the array to access the instances.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2009 Jul 31, 2009
LATEST

Your scrips seems. arr is the Vector array, which holds only Sprite object  and create 3 objects. But , I do not need this. Let me clear once again

Let, say,

var arr1:Sprite=new Sprite();

this.addChild(arr1);

arr1.x=10;

var arr2:Sprite=new Sprite();

this.addChild(arr2);

arr2.x=20;

var arr3:Sprite=new Sprite();

this.addChild(arr3);

arr3.x=10;

Now I do not want to write manually, I want to set in looping way. for example.

var i:Number;

for(i=1;i<4;i++)

{

       var arr

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines