快速連結

2010年10月15日

Load子swf檔案,並取得、呼叫其內容



父SWF檔案 - loader.swf

package {
 import flash.display.*;
 import flash.events.*;
 import flash.net.URLRequest;
 
 public class loader extends Sprite{

  var _sdr:Loader = new Loader();

  function loader(){ read(); read2();}
  
  function read(){
   _sdr.contentLoaderInfo.addEventListener(Event.COMPLETE , loadComplete,false, 0, true);
   _sdr.load(new URLRequest("a.swf"));
  }
  
  function loadComplete(e:Event):void {
   var scene= _sdr.content;   //直接讀取內容
   var c:Class= _sdr.contentLoaderInfo.applicationDomain.getDefinition( "xxxClass" ) as Class;   //讀取其中的class
   scene.init("read child function");
   addChild(scene);
   _sdr.contentLoaderInfo.removeEventListener(Event.COMPLETE , loadComplete);
  }


 }
 
}


子SWF檔案 - a.swf

package {
 import flash.display.*;
 import flash.events.*;
 
 public class _child extends Sprite{

  function _child(){ }
  
  function init(s:String){
   trace(s);
  }
 }
 
}

沒有留言:

張貼留言

歡迎大家留言提問,我會答的都會盡力回答!
如果太久沒出現回應就是我又忘記回來看留言了TAT