AS3:位于外部 swf 中的外部类中的访问函数

发布于 2024-12-11 07:13:35 字数 2439 浏览 0 评论 0原文

我正在尝试访问已加载的 swf 中具有外部类的函数。 我想避免必须将该函数放在外部 swf 中的“Main”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)
    }

//Returns "ReferenceError: Error #1069: Property setVar not find on com .view.Creative 并且没有默认值。”

这是我采取的另一种方法,但没有成功

  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()"

必须有一个解决方案......提前致谢!

I am trying to access a function in a loaded swf that has external class..
I would like to avoid having to put the function on my "Main" Doc class in the external swf
and instead access the function directly from the class

This is what ive tried so far and it's a no dice:

 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"
    }

This is the function in com.view.Creative.as

  public var storedVar:String

  public function setVar(str:String):void{
               this.storedVar = str;
               trace(storedVar)
    }

//Returns "ReferenceError: Error #1069: Property setVar not found on com.view.Creative and there is no default value."

This is the other approach I took with no success

  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///

    }

This is the function in com.view.Creative.as

   public var storedVar:String

   public function setVar(str:String):void{
               this.storedVar = str;
               trace(storedVar)
    }

//Returns "ReferenceError: Error #1069: Property setVar not found on com.view.Creative and there is no default value.
at com.util::ClickArea/completeHandler()"

There's gotta be a solution for this.....Thanks in advanced!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-12-18 07:13:35

在第二种情况下尝试以下操作:

 var myGreet:Class = event.target.applicationDomain.getDefinition("com.view.Creative") as Class;  

event.target 是您的 contentLoaderInfo 。

如果将 swf 加载到新的 ApplicationDomain 中,则无法在 currentDomain 中查找定义。

在第一种情况下,也许您已经在此别名下拥有类 Creative,但具有不同的参数,并且当您将 swf 加载到 currentDomain 时,类:“com.view.Creative”不会覆盖现有的,而是从主 swf 返回类。

in second case try this :

 var myGreet:Class = event.target.applicationDomain.getDefinition("com.view.Creative") as Class;  

event.target is Your contentLoaderInfo .

If You loading swf into new ApplicationDomain , You cannot look for definition in currentDomain .

in first case , maybe You already have class Creative under this alias but with different params and when You load swf to currentDomain , class :"com.view.Creative" will not overwrite existing , but return class from main swf.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文