自写myLoadMovie类弥补loadMovie方法的弊病
类别: Flash教程
loadMovie方法的弊病就是不能在语句后面直接对导入Movie的MC的属性进行设置,下面提供了一个实用的方法。
类文件如下:
import mx.events.EventDispatcher;
class myLoadMovie {
public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
private static var _mixin1 = EventDispatcher.initialize(myLoadMovie.prototype);
function myLoadMovie(){
}
public function GetAt(url:String, mc:MovieClip):Void{
var onwer:Object = this;
mc.loadMovie(url);
var myLoad:MovieClip = _root.createEmptyMovieClip("myLoad",10);
myLoad.onEnterFrame = function(){
var tb:Number = mc.getBytesTotal();
var lb:Number = mc.getBytesLoaded();
var percent:Number = Math.round(lb/tb*100);
if (percent == 100 and lb>1000 and tb>1000 and mc._width>0 and mc._height>0) {
onwer.dispatchEvent({type:"onLoaded", target:mc});
delete this.onEnterFrame;
}
}
}
}
class myLoadMovie {
public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
private static var _mixin1 = EventDispatcher.initialize(myLoadMovie.prototype);
function myLoadMovie(){
}
public function GetAt(url:String, mc:MovieClip):Void{
var onwer:Object = this;
mc.loadMovie(url);
var myLoad:MovieClip = _root.createEmptyMovieClip("myLoad",10);
myLoad.onEnterFrame = function(){
var tb:Number = mc.getBytesTotal();
var lb:Number = mc.getBytesLoaded();
var percent:Number = Math.round(lb/tb*100);
if (percent == 100 and lb>1000 and tb>1000 and mc._width>0 and mc._height>0) {
onwer.dispatchEvent({type:"onLoaded", target:mc});
delete this.onEnterFrame;
}
}
}
}
这个文件应该和你的FLA文件放在一起。
使用方法:
import myLoadMovie;
var mi:myLoadMovie = new myLoadMovie();
mi.GetAt("mm.jpeg",mc);
var obj:Object = new Object();
obj.onLoaded=function(eventObj:Object):Void{
var thisMc:MovieClip = eventObj.target;
thisMc._x=300;
thisMc._y=100;
thisMc._alpha = 50;
}
mi.addEventListener("onLoaded", obj);
var mi:myLoadMovie = new myLoadMovie();
mi.GetAt("mm.jpeg",mc);
var obj:Object = new Object();
obj.onLoaded=function(eventObj:Object):Void{
var thisMc: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。
-= 资 源 教 程 =-
文 章 搜 索