loadMovie方法的弊病就是不能在语句后面直接对导入Movie的MC的属性进行设置,下面提供了一个实用的方法。
类文件如下:
importmx.events.EventDispatcher;
classmyLoadMovie{
publicvaraddEventListener:Function;
publicvarremoveEventListener:Function;
privatevardispatchEvent:Function;
privatestaticvar_mixin1=EventDispatcher.initialize(myLoadMovie.prototype);
functionmyLoadMovie(){
}
publicfunctionGetAt(url:String,mc:MovieClip):Void{
varonwer:Object=this;
mc.loadMovie(url);
varmyLoad:MovieClip=_root.createEmptyMovieClip("myLoad",10);
myLoad.onEnterFrame=function(){
vartb:Number=mc.getBytesTotal();
varlb:Number=mc.getBytesLoaded();
varpercent:Number=Math.round(lb/tb*100);
if(percent==100andlb>1000andtb>1000andmc._width>0andmc._height>0){
onwer.dispatchEvent({type:"onLoaded",target:mc});
deletethis.onEnterFrame;
}
}
}
}
这个文件应该和你的FLA文件放在一起。
使用方法:
importmyLoadMovie;
varmi:myLoadMovie=newmyLoadMovie();
mi.GetAt("mm.jpeg",mc);
varobj:Object=newObject();
obj.onLoaded=function(eventObj:Object):Void{
varthisMc:MovieClip=eventObj.target;
thisMc._x=300;
thisMc._y=100;
thisMc._alpha=50;
}
mi.addEventListener("onLoaded",obj);
注:mi.GetAt("mm.jpeg",mc)中的mc是你舞台上的或者动态建立的Movie Clip的名称。也就是你想LoadMovie的MC。