我想訪問一個函數,在一個加載的swf中有外部類.. 我想避免必須將函數放在我的「Main」Doc類中外部SWF ,而是直接從類AS3:外部類中的訪問函數位於外部swf
該訪問功能是什麼香港專業教育學院試圖到目前爲止,這是一個沒有骰子:
private function startLoad(){
var loader:Loader = new Loader();
var req:URLRequest = new URLRequest("one.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(req);
}
private function onLoadComplete(e:Event):void{
var ClassDefinition:Class = e.target.applicationDomain.getDefinition("com.view.Creative") as Class;
var butn:MovieClip = new ClassDefinition(0,0);////0,0 is x and y cordinates I have in the "com.view.Creative" class
this.addChild(butn);
butn.setVar("one");////"setVar" is the function in my external swf with the class "com.view.Creative"
}
這是com.view.Creative.as
功能public var storedVar:String
public function setVar(str:String):void{
this.storedVar = str;
trace(storedVar)
}
//返回「ReferenceError:錯誤#1069:在com.view.Creative上找不到屬性setVar,並且沒有默認值。」
這是其它方法,我把沒有成功
private function startLoad(){
var appDomain:ApplicationDomain = new ApplicationDomain();
var context:LoaderContext = new LoaderContext(false, appDomain);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest("one.swf"), context);
}
private function completeHandler(event:Event):void {
var myGreet:Class = ApplicationDomain.currentDomain.getDefinition("com.view.Creative") as Class;
var app : MovieClip = new myGreet(0,0)
addChild(app);
app.setVar("one");////set var is the function in my external swf with the class "com.view.Creative" I am trying to access
//event.target.content.setVar("one");///this works if I am placing my "setVar" function on my "Main" Doc Class which I am trying to avoid///
}
這在com.view.Creative.as功能
public var storedVar:String
public function setVar(str:String):void{
this.storedVar = str;
trace(storedVar)
}
//返回「的ReferenceError:錯誤#1069:在com.view.Creative上找不到屬性setVar,並且沒有默認值。 at com.util :: ClickArea/completeHandler()「
有一個解決方案。 ...先謝謝了!
var myGreet:Class = event.target.applicationDomain.getDefinition(「com.view.Creative」)as Class;這解決了它!非常感謝@turbosqel – user992731
沒問題,您應該閱讀一些關於ApplicationDomain的內容以瞭解它是如何工作的;) – turbosqel