开发者

access dynamically loaded movieclip (stage > scrollpane > myloader > movieclip)

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.


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.


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜