2010-04-17 192 views
0

我有一個被稱爲3次的函數,我想爲它指定一個名稱。如何將動態變量名稱分配給影片剪輯或通過名稱或實例名稱引用它們?動態變量名稱

var loadedMovie:MovieClip = new MovieClip();

loadedMovie.name =「mymovie」;

loadedMovie = loadEvent.currentTarget.content; loadedMovie.x = 0; loadedMovie.y = 0;

addChild(loadedMovie);

mymovie.x = 20;

回答

1

通過將它們放入數組中來引用它們。 Someting like this(我猜你創造他們作爲對事件的迴應):

private var loadedMCs:Array = []; 
private function createMC(loadEvent:Event):void{ 
    var loadedMovie:MovieClip = loadEvent.currentTarget.content; 
    loadedMovie.x = 20; 
    loadedMovie.y = 0; 
    addChild(loadedMovie); 

    loadedMCs.push(loadedMovie); 
    // you can name them too: 
    loadedMovie.movieName = "mymovie" 

} 
// to find them: 
for each(var mc:MovieClip in loadedMCs){ 
    if (mc.movieName == "mymovie"){ 
     trace ("found"); 
    } 
}