简体   繁体   English

将外部PNG加载到AS2 SWF包装器中的AS2 SWF中

[英]Loading external pngs into an AS2 swf that is loaded into an AS3 swf wrapper

I have a Wrapper SWF that loads a series of AS2 movies. 我有一个包装SWF文件,可加载一系列AS2电影。 Each AS2 movie loads a series of .png files. 每个AS2电影都加载一系列.png文件。

AS3_wrapper.swf
 |-> AS2_1.swf
      |-> image_1.png
      |-> image_2.png
 |-> AS2_2.swf
      |-> image_1.png
      |-> image_2.png

Inside of the AS2 I listen for the load of the pngs using onLoadInit and update my UI. 在AS2内部,我使用onLoadInit监听png的负载并更新我的UI。

This works fine for the first AS2 swf. 这对于第一个AS2 SWF来说效果很好。 But when I load the second AS2 swf the onLoadInit isn't triggered for the pngs. 但是当我加载第二个AS2 SWF时,不会为png触发onLoadInit My guess is that the images are in a cache or something like that. 我的猜测是图像在缓存中或类似的东西。 I put a random string on the end of the request to try and avoid the cache but that doesn't seem to work. 我在请求的末尾放置了一个随机字符串,以尝试避免缓存,但这似乎不起作用。

The code in the as2 looks roughly like this: as2中的代码大致如下所示:

var flagLoader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = Delegate.create(this, handleImageLoad);
flagLoader.addListener(listener);
var row:MovieClip = frame1["row" + (numLoaded + 1)];
flagLoader.loadClip(predictionData[numLoaded].flag + "?r="+Math.random(), row.flag);

I'm making sure to load only one image at a time (I've read anecdotal evidence loading more than one thing at a time can confuse the MovieClipLoader ). 我确保每次仅加载一幅图像(我读过的轶事证据表明,一次加载多个对象可能会使MovieClipLoader感到困惑)。 For the first as2 file everything works great. 对于第一个as2文件,一切正常。 When I load the second as2 file the handleImageLoad never gets called. 当我加载第二个as2文件时,永远不会调用handleImageLoad

Update: Even more perplexing is if I reload the first AS2 movie (after the second AS2 movie fails to load the images) the first AS2 movie loads the images again fine. 更新:更令人困惑的是,如果我重新加载第一部AS2电影(在第二部AS2电影无法加载图像之后),第一部AS2电影又可以再次加载图像。

Update 2: After trying to change from using a MovieClipLoader to polling (as was helpfully suggested) I have found some more evidence that is relevant. 更新2:在尝试从使用MovieClipLoader更改为轮询(如有帮助的建议)之后,我发现了更多相关的证据。

When I load the first AS2 files and trace from the top level clip it prints out _root . 当我加载第一个AS2文件并从顶层剪辑进行跟踪时,它将打印出_root The second AS2 file when loaded traces the same _root . 加载后的第二个AS2文件跟踪相同的_root This lead me to check if they were clashing on names and they are. 这导致我检查它们是否与名称冲突。 Both have a child called frame . 两者都有一个叫frame的孩子。 The first one, when I trace it comes out as _root.frame as expected. 第一个,当我跟踪时,按预期以_root.frame形式出现。 The second AS2 file traces _level0.instance3.instance118.instance111.frame . 第二个AS2文件跟踪_level0.instance3.instance118.instance111.frame I'm guessing this is related to the problem. 我猜这与问题有关。

Flash is keeping the _root of the two files the same but it is changing the locations of their children (for subsequently loaded files that have children with the same names). Flash保持两个文件的_root相同,但是它正在更改其子文件的位置(对于随后加载的具有相同名称的子文件的文件)。 So either the onLoad is going to the wrong clip or the events about it loading are. 因此,要么onLoad转到错误的剪辑,要么有关其加载的事件。

Once every 3-4 years I come across a problem that I think will finally break me... 每3-4年一次,我遇到一个问题,我认为它将最终使我失望...

I came across this post when trying to figure out why even though I was successfully loading my AVM1 movie into an AVM2 movie file, the AVM1 file was not running as expected. 当我试图弄清楚为什么即使我成功地将AVM1电影加载到AVM2电影文件中时,我也遇到了这篇文章。

Having solved the initial huge issue of not being able to communicate between AS2 - AS3 files I couldn't believe it when the AVM1 movie always seemed to halt shortly after starting playback. 解决了最初无法在AS2-AS3文件之间进行通信的巨大问题之后,当AVM1电影在开始播放后似乎总是停顿下来时,我简直不敢相信。

For me, the MovieClipLoader loadClip() methods were not firing any progress or completed events which was consequently causing my file to stop playback completely, as you both suggested. 对我来说,MovieClipLoader loadClip()方法没有触发任何进度或完成的事件,因此导致文件完全停止播放,正如你们俩都建议的那样。

Your suggestion to run an interval after the loadClip call to compare bytes loaded to bytes total worked for me. 您的建议是在loadClip调用之后运行一个间隔,以将加载的字节与字节总数进行比较,这对我来说很有效。

Thank you Thank you Thank you Thank you Thank you ! 谢谢谢谢谢谢谢谢谢谢! :D :d

Running AS2 under AS3 seem to introduce some latency issues.... you need to poll the loaded swf a few times before it recognizes it's loaded. 在AS3下运行AS2似乎会引入一些延迟问题。...您需要先轮询已加载的swf几次,然后它才能识别已加载。

I'm in a similar situation ... an AS3 Shell loading a large and complicated AS2 application with many external swfs, dependencies, etc. Wat I had to do was to run an interval after the loadClip call to compare bytes loaded to bytes total... then when they equaled each other (but exceeded 4) I could safely fire the onLoadInit function that would otherwise never fire. 我处在类似的情况下……一个AS3 Shell加载具有许多外部swfs,依赖项等的大型且复杂的AS2应用程序。我要做的是在loadClip调用之后运行一个间隔,以比较加载的字节与总的字节数...然后当它们彼此相等(但超过4)时,我可以安全地触发onLoadInit函数,否则该函数将永远不会触发。

So you lose all the init, progress and error events that MovieClipLoader gave you in AS2.. you're going back to FP5 and FP6 days but it does seem to work reliably. 因此,您会丢失MovieClipLoader在AS2中给您的所有初始化,进度和错误事件。.您要回到FP5和FP6的日子,但它确实可以可靠地工作。 Would love to hear about other peoples experiences and if there is a better way around this. 很想听听其他人的经历,以及是否有更好的解决办法。

James, 詹姆士,

You're right, I've also noticed that _root vs _level0.instance3.instance118 read-out in the trace stack you you described, it must be related to the AVM1 content and how AVM2 movies handle it. 没错,我还注意到您描述的跟踪堆栈中的_root vs _level0.instance3.instance118读数,它必须与AVM1内容以及AVM2电影如何处理它有关。

Polling won't always work but you can use it to see what's happening after you fire the loadClip() method. 轮询并非总能正常工作,但是您可以在启动loadClip()方法后使用它来查看正在发生的情况。 Do you see your bytesLoaded as undefined ? 您是否看到bytesLoaded未定义 Or maybe the swf is loaded but you can't access properties of it, such as a variable declared on the main timeline of your swf. 也许已加载了swf,但是您无法访问其属性,例如在swf主时间轴上声明的变量。 I've gotten pretty deep into this problem and found that essentially you have two or three ways of working around these problems. 我已经对这个问题进行了深入研究,发现实际上您有两种或三种方法来解决这些问题。 Polling the AS2 container is the first step to see what is failing.... 轮询AS2容器是了解失败原因的第一步。

Can you get your .pngs to load in using loadMovie instead of MovieClipLoader ? 您可以使用loadMovie而不是MovieClipLoader来加载.png文件吗?

Have you tried running your example under FP10.1? 您是否尝试过在FP10.1下运行示例? Oddly enough a lot of these issues go away! 奇怪的是,这些问题很多都消失了!

Depending on the complexity of your AS2 application this can be a tough problem to work around. 根据您的AS2应用程序的复杂性,这可能是一个很难解决的问题。

You checked this out: http://fladdict.net/blog-en/2007/06/avm2loader-class.html 您已检查了此内容: http : //fladdict.net/blog-zh/2007/06/avm2loader-class.html

thanks, Geoff 谢谢,杰夫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM