我有一个被调用3次的函数,我想要给它分配一个名字。如何为动画片段指定动态变量名称或按名称或实例名称引用它们?
var loadedMovie:MovieClip = new MovieClip();
loadedMovie.name =“mymovie”;
loadedMovie = loadEvent.currentTarget.content; loadedMovie.x = 0; loadedMovie.y = 0;
的addChild(loadedMovie);
mymovie.x = 20;
答案 0 :(得分:1)
通过将它们放入数组来引用它们。 像这样的东西(我猜你创建它们作为对事件的回应):
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" );
}
}