2010-07-09 3 views
0

Je suis assez inexpérimenté avec Action Script mais j'ai beaucoup cherché sur les forums pour essayer de trouver une solution à ce problème simple.nom du MovieClip séquentiel dans AS3

Je crée plusieurs copies d'un MovieClip mais j'ai besoin qu'elles aient des noms différents.

// this array gets several cities 
var cities:Array = new Array(
{ nome:"london", pos_x:20, pos_y:10 }, 
{ nome:"nyc", pos_x:210, pos_y:210 } 
); 

// now i would loop the cities array and create a copy of city_img for each 
var k:*; 
for each (k in cities) { 
    var mov:city_img = new city_img(); // city_img is a movieclip 
    addChild(mov); 
    mov.x = k.pos_x; 
    mov.y = k.pos_y; 
    mov.id = i; 
    i++; 
} 

Ce code fonctionne mais, comme prévu, mov obtient id = 1. Même si deux MovieClips sont dessinés sur scène.

Quelqu'un peut-il m'aider sur attribuer différents noms pour chaque MovieClip?

Répondre

1

Utilisez la propriété name non?

// this array gets several cities 
var cities:Array = new Array(
{ nome:"london", pos_x:20, pos_y:10 }, 
{ nome:"nyc", pos_x:210, pos_y:210 } 
); 

// now i would loop the cities array and create a copy of city_img for each 
var k:*; 
var i:int=0; 
for each (k in cities) { 
    var mov:city_img = new city_img(); // city_img is a movieclip 
    addChild(mov); 
    mov.x = k.pos_x; 
    mov.y = k.pos_y; 
    mov.id = i; 
    mov.name=k.nome; // <-- here set the name of the movie clip 
    i++; 
} 
+0

getChildByName ("london"). Play(); –

+0

C'est parfait! ;) Je vous remercie. – Frankie

Questions connexes