【问题标题】:access of content of loaded swf访问加载的 swf 的内容
【发布时间】:2013-04-11 11:51:58
【问题描述】:

我想访问已加载的SWF 文件的内容。我使用了以下代码,

function _browse(e:MouseEvent):void
{  
     loader.load(new URLRequest("artwork3.swf.swf"));
     loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loading);
     target_clip.addChild(loader);
}

function loading(event:Event)
{
     trace(target_clip.getChildAt(0));
     trace(target_clip.getChildAt(1));
}

请帮帮我。

【问题讨论】:

    标签: actionscript-3 flash actionscript flash-builder action


    【解决方案1】:
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener( Event.COMPLETE, handleComplete );
    var request:URLRequest = new URLRequest("artwork3.swf.swf");
    loader.load(request);
    
    protected function handleComplete(event:Event):void
    {   
        DisplayObject loadedSwf = target_clip.addChild(event.currentTarget.content as DisplayObject) as DisplayObject;
        //you can access variables from loaded swf
        trace(loadedSwf.name);
    }
    

    【讨论】:

      【解决方案2】:
       function _browse(e:MouseEvent):void
          {  
               loader.load(new URLRequest("artwork3.swf.swf"));
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loading);
               target_clip.addChild(loader);
          }
          function loading(event:Event)
          {
               var myLoadedSwf:MovieClip = loader.content as MovieClip;
      
               trace(myLoadedSwf.getChildAt(0));
               trace(myLoadedSwf.getChildAt(1));
               //trace(target_clip.getChildAt(0));
               //trace(target_clip.getChildAt(1));
          }
      

      【讨论】:

      • 显示错误,TypeError:错误 #1009:无法访问空对象引用的属性或方法。
      • 抱歉,错字,应该是 myLoadedSwf 而不是 myLoadedSwf_clip。我更正了代码
      【解决方案3】:

      试试MovieClip(loader.content),而不是像这样的target_clip,

      function _browse(e:MouseEvent):void
      {  
           loader.load(new URLRequest("artwork3.swf.swf"));
           loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loading);
           target_clip.addChild(loader);
      }
      
      function loading(event:Event)
      {
           trace(MovieClip(loader.content).getChildAt(0));
           trace(MovieClip(loader.content).getChildAt(1));
      }
      

      祝你好运。

      【讨论】:

        猜你喜欢
        • 2012-02-23
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        • 1970-01-01
        • 2011-02-03
        • 2015-04-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多