2012-06-06 6 views
0

mon but est d'avoir plusieurs objets (animés) chargés dans ma scène comme un MovieClip trought un tableau.Tableaux comme "movieclip" actionscript 3.0

Mon code actuel:

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

Donc, fondamentalement, ma question est de savoir comment puis-je obtenir tous ces faire l'animation avec "gotoAndStop (1)" et ou "gotoAndStop (2)", ainsi de suite et ainsi de suite .

EDIT: le fichier externe pour le charger, dans le 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; 



    } 

Répondre

3

Est-ce ce dont vous avez besoin?

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

SWF est un MovieClip. Vous devez accéder au contenu du chargeur. Je ne suis pas sûr comment appeler la variable comme dans votre code vous utilisez vijand pour un tableau et pour un chargeur.

Exemple de 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... 
} 
+0

Le problème est que le .swf chargé n'est pas un MovieClip et donc je ne peux pas contrôler. – PlayerX

+0

S'il vous plaît jeter un oeil à la réponse mise à jour ... – strah

+0

Merci. Ça marche! – PlayerX

1

écrire une méthode pour cela.

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

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

    return array; 
}