简体   繁体   中英

Arrays as “movieclip” actionscript 3.0

my goal is to have multiple (animated) objects loaded in my stage as a movieclip trought an Array.

My current code:

var vijand:Array;

vijand = new Array  ;
vijand.push(new Vijand(-580,-200));
vijand.push(new Vijand(-500,-200));
vijand.push(new Vijand(-420,-200));
for (var n:int = 0; n < vijand.length; n++)
{
    this.addChild(vijand[n]);

}
    //not working part. They do load on my stage. But I cant control the animation within the file(its a .SWF file I load)

    for (var n:int = 0; n < vijand; n++){
   gotoAndStop(1)
       }

So basically my question is how can I get all these doing the animation with "gotoAndStop(1)" and or "gotoAndStop(2)", so on and so on.

EDIT: the external file to load it, in Code

public function Vijand(positieX:int, positieY:int)
    {
        vijand = new Loader();
        vijand.load(new URLRequest("resources/vijand.swf"))
        this.addChild(vijand);
        vijand.x = positieX;
        vijand.y = positieY;



    }

Is that what you need?

var vijand:Array;

vijand = new Array  ;
vijand.push(new Vijand(-580,-200));
vijand.push(new Vijand(-500,-200));
vijand.push(new Vijand(-420,-200));
for (var n:int = 0; n < vijand.length; n++)
{
    this.addChild(vijand[n]);
    MovieClip(vijand[n]).gotoAndStop(1); //or gotoAndPlay(1) - depending on your needs

}

EDIT

Loaded SWF is a MovieClip. You need to access loader's content. I am not sure how to call the variable as in your code you use vijand for an Array and for a Loader.

Sample code:

var myMovieClip:MovieClip;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("resources/vijand.swf"));

function onLoaded(e:Event):void
{
    myMovieClip = MovieClip(loader.content);
    myMovieClip.gotoAndStop(1);
    //you can add this MovieClip to the array and so on...
}

Write a method for that.

function animateAll(array:Array):Array
{
  if (!array || array.length == 0) return array

  for each(var m:MovieClip in array) m.gotoAndStop(1);

  return array;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM