2010-11-01 05:10

[ActionScript] loadMovieClip

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


使用方式:
  1. var container:MovieClip = createEmptyMovieClip("container", this.getNextHighestDepth()); 
  2.  
  3. container._x = container._y = 0; 
  4. container.visible = false; 
  5.  
  6. container.loadMovieClip("vodBlock.swf", function(container:MovieClip) { 
  7.    trace("load complete"); 
  8.    container._visible = false; 
  9. }); 

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

0 回應: