简体   繁体   English

AS3:从外部加载的SWF获取信息

[英]AS3: Getting information from an externally loaded SWF

So I have an SWF that I've made and I need to appened some instructions to the beginning of the project. 所以我有一个SWF文件,需要在项目开始时加上一些说明。 I figured the easiest way to do this was to make the animation in a separate SWF then import it to the start of the first one. 我认为最简单的方法是在单独的SWF中制作动画,然后将其导入到第一个动画的开头。 My problem is that I can't find a reliable way to tell when the first SWF is finished playing. 我的问题是,找不到第一个SWF播放完毕的可靠方法。 I've googled the heck out of this but I can't seem to find anything that works. 我已经用谷歌搜索了一下,但似乎找不到任何有效的方法。 For some bizarre reason, no matter what I do the program seems to think that the external SWF only has 2 frames, if I put an ENTER_FRAME listener and trace externalSWF.currentFrame I get "1, 1, 2, 2, 2, 2, 2, 2..." My code looks something like this. 出于某种奇怪的原因,无论我做什么,程序似乎都认为外部SWF仅具有2帧,如果我放置ENTER_FRAME侦听器并跟踪externalSWF.currentFrame,则会得到“ 1、2、2、2、2、2” 2,2 ...”我的代码看起来像这样。

var ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
ldr.load(new URLRequest("Instructions.swf"));

function loaded(e:Event){
    trace("Loaded");
    var extSwf = ldr.content as MovieClip;
    addChild(extSwf);
    trace(extSwf.totalFrames);//Returns 2
}

Has anyone else had similar problems with external SWFs? 外部SWF是否有其他类似的问题?

Also, for the record, the external SWF plays properly when I add it as a child. 另外,作为记录,当我将其添加为子级时,外部SWF可以正常播放。 The problem is removing it from the stage when it's done playing. 问题是在完成播放后将其从舞台上删除。 It's interactive so I can't just do a frame count. 它是交互式的,所以我不能只进行帧计数。

Edit: So I tried doing a getQualifiedClassName() call on extSwf and I got "Instructions_fla::MainTimeline_ Preloader _" which could explain the frame discrepency. 编辑:因此,我尝试对extSwf进行getQualifiedClassName()调用,并且得到了“ Instructions_fla :: MainTimeline_ Preloader _”,它可以解释帧差异。 How can I have access to the actual timeline? 我怎样才能访问实际的时间表?

So I found the solution to the problem. 因此,我找到了解决问题的方法。 Like I said in the edit, I was getting "Instructions_fla::MainTimeline_Preloader_" as the QualifiedClassName so I googled that and found someone saying that Flash CS5 exports your SWFs with a preloader by default so that was what was being attached to extSwf and not the MovieClip itself. 就像我在编辑中说的那样,我获得了“ Instructions_fla :: MainTimeline_Preloader_”作为QualifiedClassName,因此我用Google搜索了一下,发现有人说Flash CS5默认情况下使用预加载器导出SWF,因此这是附加到extSwf而不是MovieClip本身。 The way to fix it is to go into File>Actionscript Settings>Library Path, and change Default linkage to "Merged Into Code". 解决此问题的方法是进入“文件”>“动作脚本设置”>“库路径”,然后将“默认”链接更改为“合并到代码中”。 This appears to only happen in CS5. 这似乎仅在CS5中发生。 I found the solution here: http://blog.flash-core.com/?p=142 我在这里找到了解决方案: http : //blog.flash-core.com/?p=142

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

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