访问动态加载的影片剪辑(舞台 > 滚动窗格 > myloader > 影片剪辑)

发布于 2024-12-09 21:36:00 字数 2002 浏览 0 评论 0 原文

我想做的是

   snapText = scrollPane.source.textSnapshot;

从外部 swf 访问。我已经尝试过:

  trace("-->: "+scrollPane.source.textSnapshot.getText(0, 1000));
  trace("-->: "+myLoader.content.textSnapshot.getText(0, 1000));
  trace("-->: "+mc.textSnapshot.getText(0, 1000));
  trace("-->: "+mc.getChildAt(0).textSnapshot.getText(0, 1000));
  trace("-->: "+mc.getChildByName(myLoader).textSnapshot.getText(0, 1000) );
  trace("-->: "+scrollPane.content.textSnapshot.getText(0, 100));

所有这些都没有结果。顺便说一句:

  mc.getChildAt(0).textSnapshot.getText(0, 1000)

抛出错误:

  1119: Access of possibly undefined property textSnapshot through a reference with static type flash.display:DisplayObject.

虽然我知道该方法在那里。

上述所有代码都在函数 checkHandler: 中运行,

 myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, checkHandler);

因此 swf 应该已完全加载。 文本也在那里,我已经用 swf 反编译器检查过。 带有加载程序的影片剪辑是这样创建的,

 scrollPane = MovieClip(root).scrollPaneOnStage;
 myLoader.load(new URLRequest("tmp1.swf"));
 mc.addChild(myLoader);
 scrollPane.source = mc;

提前致谢!

更新 - 仍未解决

我现在正在访问 HotN 指出的 swf。

  function checkHandler(evt:Event):void {

         libMC  = evt.target.content as MovieClip;
         libMC.gotoAndStop(0); 
          trace(libMC.textSnapshot.getText(0, 100));
         snapText = libMC.textSnapshot;
        scrollPane.source = mc;
    }

这首先导致了一个错误,因为 as3 脚本中的加载器无法加载 as2 电影(即 AVM1)。所以我创建了一个AVM2 swf,这导致了错误:错误#2000:没有活动的安全上下文。作为解决方案,我使用了http://www.igorcosta.org/?p=231 加载 swf,但仍然无法 访问textSnapshot:

  trace(libMC.textSnapshot.getText(0, 100));

不返回任何内容,也不抛出错误!

顺便说一句:虽然我可以更改 swf 的格式,但我无法真正更改文件本身,因为它是自动生成的。

what I'm trying to do is accessing

   snapText = scrollPane.source.textSnapshot;

from an external swf. I've tried:

  trace("-->: "+scrollPane.source.textSnapshot.getText(0, 1000));
  trace("-->: "+myLoader.content.textSnapshot.getText(0, 1000));
  trace("-->: "+mc.textSnapshot.getText(0, 1000));
  trace("-->: "+mc.getChildAt(0).textSnapshot.getText(0, 1000));
  trace("-->: "+mc.getChildByName(myLoader).textSnapshot.getText(0, 1000) );
  trace("-->: "+scrollPane.content.textSnapshot.getText(0, 100));

all of which were fruitless. BTW:

  mc.getChildAt(0).textSnapshot.getText(0, 1000)

throws the error:

  1119: Access of possibly undefined property textSnapshot through a reference with static type flash.display:DisplayObject.

although I know the method is there.

all of the above code is run in the function checkHandler:

 myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, checkHandler);

so the swf should have been completly loaded.
The text is also there, I've checked with an swf decompiler.
the movieclip with the loader is created like this

 scrollPane = MovieClip(root).scrollPaneOnStage;
 myLoader.load(new URLRequest("tmp1.swf"));
 mc.addChild(myLoader);
 scrollPane.source = mc;

thanks in advance!

UPDATE - still not resolved

I'm now accessing the swf as pointed out by HotN.

  function checkHandler(evt:Event):void {

         libMC  = evt.target.content as MovieClip;
         libMC.gotoAndStop(0); 
          trace(libMC.textSnapshot.getText(0, 100));
         snapText = libMC.textSnapshot;
        scrollPane.source = mc;
    }

This resulted at first in an error, because the loader in an as3 script cant load an as2 movie (ie. AVM1). so I created an AVM2 swf which led to the error: Error #2000: No active security context. As a solution I used a class from http://www.igorcosta.org/?p=231 to load the swf, but still cant access the textSnapshot:

  trace(libMC.textSnapshot.getText(0, 100));

doesnt return anything and doesnt throw an error!

BTW: while I could change the format of the swf, I cant really change the file itself since it's automatically generated.

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

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

发布评论

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

评论(3

冷血 2024-12-16 21:36:00

为了引用加载的 swf 中的任何内容,您需要检查用于加载 swf 的加载器的内容。这将为您提供该参考:

function checkHandler(e:Event):void {
    var loadedSWF:Object = e.target.content;
}

通过浏览 loadedSWF,您可以获取 swf 的内容(假设它们已设置为公共可见性)。

In order to reference anything in a loaded swf, you need to go through the content of the loader you used to load the swf. This will get you that reference:

function checkHandler(e:Event):void {
    var loadedSWF:Object = e.target.content;
}

By going though loadedSWF, you can then get to the contents of the swf, assuming they're set to public visibility.

风月客 2024-12-16 21:36:00

您是否使用TLF引擎(TLF文本字段)?加载 SWF 并尝试访问这些加载的 SWF 的属性或方法时,Flash CS5 TLF 引擎会导致一些错误。您可以在这篇博客文章中阅读所有相关内容 史蒂文·萨克斯

如果是这样,解决方案非常简单:将您的 TLF 文本字段更改为常规文本字段(它被标记为经典文本,文本字段属性面板上有一个选择器)并且(希望)一切都会正常工作,没有进一步的代码更改。

如果您需要 TLF 文本并且无法使用常规文本,您可以在此 Adobe 技术说明

希望这有帮助!

Are you using the TLF Engine (TLF textfields)? The Flash CS5 TLF Engine causes some errors when loading SWFs and trying to access properties or methods of those loaded SWFs. You can read all about it in this blog post by Steven Sacks.

If so, the solution is quite simple: Change your TLF Textfields to regular ones (it's labelled Classic Text, there is a selector on the TextField Properties panel) and (hopefully) everything will work fine, with no further code change.

If you need TLF texts and can't do with regular ones, you can find a couple of solutions (more like workarounds, but whatever) in this Adobe Technote.

Hope this helps!

提笔书几行 2024-12-16 21:36:00

所以这花了我很长时间,但我已经弄清楚了。

      //... {

        loader = new Loader();  
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, checkHandler);
        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
        var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain); 
        context.checkPolicyFile = false;
        loader.load(new URLRequest("tmp1.swf"), context);


      //..... }

      function checkHandler(evt:Event):void {

        loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,checkHandler);

        libMC  = loader.content as MovieClip;

                    //works now!
            libMC.textSnapshot.getText(100, 200);

        scrollPane.source = libMC;


    }

所以诀窍是使用标准加载器函数,就像多次建议的那样。然而,flash 不知何故弄乱了我本地电脑上的安全/沙箱设置,从而导致错误#2000:没有活动的安全上下文。然而,当上传到远程服务器时它仍然工作正常,这很奇怪。您可以在“文件”>“本地播放设置”下将本地播放设置设置为“仅访问本地文件”。发布设置,但这对我来说根本没有帮助......

So this has taken me enterily too long, but I got it figured out.

      //... {

        loader = new Loader();  
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, checkHandler);
        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
        var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain); 
        context.checkPolicyFile = false;
        loader.load(new URLRequest("tmp1.swf"), context);


      //..... }

      function checkHandler(evt:Event):void {

        loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,checkHandler);

        libMC  = loader.content as MovieClip;

                    //works now!
            libMC.textSnapshot.getText(100, 200);

        scrollPane.source = libMC;


    }

so the trick was using the standard loader function like suggested so many times. however flash somehow messes up the security/sandbox settings on my local pc, which resulted in a Error #2000: No active security context. however it still worked fine when uploaded to a remote server, which is strange. you can set the local playback settings to "access local files only" under File > Publish Settings, but that didnt help at all in my case...

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