0

我的目标是在我的舞台上加载多个(动画)对象,作为一个电影剪辑 trought 一个数组。

我当前的代码:

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)
       }

所以基本上我的问题是我怎样才能让所有这些用“gotoAndStop(1)”和/或“gotoAndStop(2)”来做动画,依此类推。

编辑:在代码中加载它的外部文件

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;



    }
4

2 回答 2

2

那是你需要的吗?

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

}

编辑

加载的 SWF一个电影剪辑。您需要访问加载程序的内容。我不确定如何在vijand用于数组和加载器的代码中调用变量。

示例代码:

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...
}
于 2012-06-06T15:10:52.543 回答
1

为此编写一个方法。

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

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

  return array;
}
于 2012-06-06T14:40:50.297 回答