【问题标题】:pass var values from one swf to another swf who is loaded inside the firts one in AS3将 var 值从一个 swf 传递到另一个 swf,后者在 AS3 中的第一个 swf 中加载
【发布时间】:2011-01-02 01:52:36
【问题描述】:

我使用此方法将 SWF 加载到另一个 SWF 中: (这段代码在 main.swf 中)

function loadImage(url:String):void {
imageLoader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
loadImage("test1.swf");

function imageLoaded(e:Event):void {
MyMovieClip.addChild(imageLoader); 
} 

认为 test1.swf 需要加载器 swf (main.swf) 中的值,我该如何传递该值?谢谢!

【问题讨论】:

    标签: flash actionscript-3


    【解决方案1】:

    您可以为加载的 SWF ( test1.swf ) 创建一个类,您可以将其分配给 Document 类。

    在这个类中,为您需要传递给加载的 SWF 的值创建一个设置器。

       //Here the choice of Array is arbitrary & depends on what values
       //you need to pass to the SWF...
       private var _params:Array;
       public function set params( value:Array ):void
       {
          _params = value;
       }
    

    然后在您的 Main 类中,您可以执行以下操作:

      //Assuming you'd like to pass a number of values...
      function imageLoaded(e:Event):void {
    
          var content:MovieClip = imageLoader.content as CustomClass;
          content.params = [ value1 , value2... valueN];
          MyMovieClip.addChild(content);
      } 
    

    【讨论】:

    【解决方案2】:

    您需要访问加载程序的内容才能执行此操作。在您的 imageLoaded 函数中执行此操作。

    ( e.target.content as Object ).someParam = "whatever";
    

    有许多安全限制需要考虑,(这称为跨脚本),但如果您从同一个域加载两个 swf,则应该没有问题。

    【讨论】:

    • 顺便说一句,这到底是怎么写的?我的意思是它如何适合她编写的确切加载器功能?我也有同样的问题:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    相关资源
    最近更新 更多