【发布时间】:2011-12-13 09:04:50
【问题描述】:
我正在尝试访问已加载的具有外部类的 swf 中的函数.. 我想避免将函数放在外部 swf 中的“主要”Doc 类中 而是直接从类中访问函数
这是我迄今为止尝试过的,而且是没有骰子的:
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 并且没有默认值。 在 com.util::ClickArea/completeHandler()"
必须有一个解决方案......在此先感谢!
【问题讨论】:
标签: actionscript-3 oop class dynamic