如何控制动态加载的SWF

时间:2021-09-13 00:05:36

I have a flash piece that loads external SWF files. I need to be able to move the loaded swf file to the next frame in the main timeline.

我有一个加载外部SWF文件的flash片。我需要能够将加载的swf文件移动到主时间轴中的下一帧。

Here's the code snippet:

这是代码片段:

var request:URLRequest = new URLRequest(file);
loader.load(request);
var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();

If I run a trace on swfTimeline, I get a null object reference. I think I found a way around that, but now the issue I'm having is that the loaded SWF is ActionScript 2 and AS3 doesn't seem to want to handle the AS2 SWF as a normal movie clip.

如果我在swfTimeline上运行跟踪,我会得到一个空对象引用。我想我找到了解决方法,但现在我遇到的问题是加载的SWF是ActionScript 2而AS3似乎不想将AS2 SWF作为普通的影片剪辑来处理。

6 个解决方案

#1


You need to add an event listener o the loader first so that you know when the load is complete. So from your code snippet i would suggest something like

您需要首先在加载器中添加事件侦听器,以便了解加载何时完成。所以从你的代码片段我会建议像

var request:URLRequest = new URLRequest(file);
loader.addEventListener(Event.COMPLETE, function(event : Event) : void
{
var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();
});
loader.load(request);

Lots of different ways to organise this code but that should do the trick

有很多不同的方法来组织这个代码,但这应该可以解决问题

#2


Use the content property of the Loader object in which you are loading the SWF into. For example...

使用要在其中加载SWF的Loader对象的content属性。例如...

var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();

#3


If you want to load the symbols from Flash to Flex then this should help.

如果要将符号从Flash加载到Flex,那么这应该会有所帮助。

loader.contentLoaderInfo.applicationDomain.getDefinition("here linkage name") as Class

This code enables a Movieclip to be placed on stage, with it's timeline-based actionscript (stop commands at the end of the animation, etc.) intact. One way to use this is the following:

此代码允许将Movieclip放置在舞台上,其基于时间轴的动作脚本(动画结束时停止命令等)保持不变。使用它的一种方法如下:

var c:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("BA_doors") as Class
_animation = new c() as MovieClip
addChild(_doors)

#4


If you get a null trying to get to the content, you might have to wait for a loading complete event:

如果您尝试访问内容时出现null,则可能必须等待加载完成事件:

   swfLoader.addEventListener(Event.COMPLETE, onSwfLoaded);

Once the swf has completely loaded, then you won't get a null any more.

一旦swf完全加载,那么你将不再获得null。

One thing to be careful of is that even before you get the COMPLETE event, the main timeline on the swf will start running. You'll need to have a stop() on the first frame of the flash movie to do what you're trying to do... and even then it can be problematic. Sometimes the main timeline has a mind of its own.

有一点需要注意的是,即使在获得COMPLETE事件之前,swf上的主时间轴也将开始运行。你需要在flash电影的第一帧上设置一个stop()来做你想要做的事情......即使这样,它也会有问题。有时主时间轴有自己的想法。

In my project, we recently decided to totally clear the main timeline, and load movies out of the symbol library... Loading movieclips as symbols gives you complete control, but you would have to use transforms to get them placed correctly (since you don't have a main stage anymore.)

在我的项目中,我们最近决定完全清除主时间轴,并从符号库中加载电影......将动画片段加载为符号可让您完全控制,但您必须使用变换才能正确放置它们(因为您不能再也没有主舞台了。)

As long as you are using AS3 flash9 movie clips, you'll have complete control from Flex.

只要您使用AS3 flash9影片剪辑,您就可以完全控制Flex。

Enjoy!

#5


Shouldfnt it be..

应该是......

loader.currentTarget.content as MovieClip;

#6


As far as I know - the only way for an AVM2 movie (your AS3 movie) to talk to an AVM1 movie (your as2 swf) is to use a LocalConnection object.

据我所知 - AVM2电影(您的AS3电影)与AVM1电影(您的as2 swf)通信的唯一方法是使用LocalConnection对象。

As to your first question - I am fighting the same... I need access to the loader.content property before the complete event fires.

关于你的第一个问题 - 我正在反击...我需要在完成事件触发之前访问loader.content属性。

Good luck!

Regards,

Chris

#1


You need to add an event listener o the loader first so that you know when the load is complete. So from your code snippet i would suggest something like

您需要首先在加载器中添加事件侦听器,以便了解加载何时完成。所以从你的代码片段我会建议像

var request:URLRequest = new URLRequest(file);
loader.addEventListener(Event.COMPLETE, function(event : Event) : void
{
var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();
});
loader.load(request);

Lots of different ways to organise this code but that should do the trick

有很多不同的方法来组织这个代码,但这应该可以解决问题

#2


Use the content property of the Loader object in which you are loading the SWF into. For example...

使用要在其中加载SWF的Loader对象的content属性。例如...

var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();

#3


If you want to load the symbols from Flash to Flex then this should help.

如果要将符号从Flash加载到Flex,那么这应该会有所帮助。

loader.contentLoaderInfo.applicationDomain.getDefinition("here linkage name") as Class

This code enables a Movieclip to be placed on stage, with it's timeline-based actionscript (stop commands at the end of the animation, etc.) intact. One way to use this is the following:

此代码允许将Movieclip放置在舞台上,其基于时间轴的动作脚本(动画结束时停止命令等)保持不变。使用它的一种方法如下:

var c:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("BA_doors") as Class
_animation = new c() as MovieClip
addChild(_doors)

#4


If you get a null trying to get to the content, you might have to wait for a loading complete event:

如果您尝试访问内容时出现null,则可能必须等待加载完成事件:

   swfLoader.addEventListener(Event.COMPLETE, onSwfLoaded);

Once the swf has completely loaded, then you won't get a null any more.

一旦swf完全加载,那么你将不再获得null。

One thing to be careful of is that even before you get the COMPLETE event, the main timeline on the swf will start running. You'll need to have a stop() on the first frame of the flash movie to do what you're trying to do... and even then it can be problematic. Sometimes the main timeline has a mind of its own.

有一点需要注意的是,即使在获得COMPLETE事件之前,swf上的主时间轴也将开始运行。你需要在flash电影的第一帧上设置一个stop()来做你想要做的事情......即使这样,它也会有问题。有时主时间轴有自己的想法。

In my project, we recently decided to totally clear the main timeline, and load movies out of the symbol library... Loading movieclips as symbols gives you complete control, but you would have to use transforms to get them placed correctly (since you don't have a main stage anymore.)

在我的项目中,我们最近决定完全清除主时间轴,并从符号库中加载电影......将动画片段加载为符号可让您完全控制,但您必须使用变换才能正确放置它们(因为您不能再也没有主舞台了。)

As long as you are using AS3 flash9 movie clips, you'll have complete control from Flex.

只要您使用AS3 flash9影片剪辑,您就可以完全控制Flex。

Enjoy!

#5


Shouldfnt it be..

应该是......

loader.currentTarget.content as MovieClip;

#6


As far as I know - the only way for an AVM2 movie (your AS3 movie) to talk to an AVM1 movie (your as2 swf) is to use a LocalConnection object.

据我所知 - AVM2电影(您的AS3电影)与AVM1电影(您的as2 swf)通信的唯一方法是使用LocalConnection对象。

As to your first question - I am fighting the same... I need access to the loader.content property before the complete event fires.

关于你的第一个问题 - 我正在反击...我需要在完成事件触发之前访问loader.content属性。

Good luck!

Regards,

Chris