2010-11-01

[ActionScript] loadMovieClip

原生的 loadMovie 少了 onComplete 的追蹤,而 MovieClipLoader 使用起來又太囉唆,索性就對 MovieClip 的 prototype 上加了 loadMovieClip function,至少會撰寫時快樂一點。
MovieClip.prototype.loadMovieClip = function(src:String, onComplete:Function) :MovieClip {
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener({onLoadInit:onComplete});
    mcLoader.loadClip(src,this);
    return this;
};


使用方式:
var container:MovieClip = createEmptyMovieClip("container", this.getNextHighestDepth());

container._x = container._y = 0;
container.visible = false;

container.loadMovieClip("vodBlock.swf", function(container:MovieClip) {
    trace("load complete");
    container._visible = false;
});

參考來源:
Flash CS4 Professional ActionScript 2.0: loadClip (MovieClipLoader.loadClip 方法)

0 回應: