Flex 将 SWF 加载为 Sprite。 如何将其加载为影片剪辑?

发布于 2024-07-21 05:22:03 字数 764 浏览 7 评论 0原文

我在执行以下操作时将 SWFLoader.content 转换为 MovieClip 实例时遇到问题(TheFlashCanon 的优秀教程 )使 SWF 与 Flex 进行通信。 所加载的 SWF 是使用 Flash CS3(使用 actionscript 3)编译的。

但是,当我尝试获取 SWFLoader 的内容并将其转换为 MovieClip 实例时,我总是收到此错误:

TypeError:错误#1034:类型强制 失败:无法转换 maix::main_maix@49f94ec1 至 flash.display.MovieClip。 在 test1/onLoadMinigameComplete()[/Users/chiyin/Documents/Flex 建设者 3/SimpleGirlfriend/src/Main.as:68]

其中 maix::main_maix@49f94ec1 是我的电影的一个实例。

我究竟做错了什么? 否则,加载的 swf 可以正常播放,并且不会表示为 AVM1Movie。

更新:发现 SWF 是作为 Sprite 而不是 Movieclip 导入的。 如何强制 SWFLoader 将 SWF 作为 Movieclip 而不是 Sprite 对象加载?

I have a problem converting SWFLoader.content into a MovieClip instance while following (TheFlashCanon's excellent tutorial) on making a SWF communicate with Flex. The SWF loaded in question is compiled using Flash CS3 (using actionscript 3).

However, when I try to get the content of the SWFLoader and convert it into a MovieClip instance, I always get this error:

TypeError: Error #1034: Type Coercion
failed: cannot convert
maix::main_maix@49f94ec1 to
flash.display.MovieClip. at
test1/onLoadMinigameComplete()[/Users/chiyin/Documents/Flex
Builder
3/SimpleGirlfriend/src/Main.as:68]

where maix::main_maix@49f94ec1 is an instance of my movie.

What am I doing wrong? The loaded swf plays fine otherwise, and is not denoted as a AVM1Movie.

Update: Found out that the SWF is imported as a Sprite instead of a Movieclip. How do I force the SWFLoader to load the SWF as a Movieclip instead of a Sprite object?

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

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

发布评论

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

评论(2

终止放荡 2024-07-28 05:22:03

main_maix 看起来是正在加载的 swf 的文档类。如果是这样,main_maix 应该扩展 MovieClip 而不是 Sprite

public class main_maix extends MovieClip 

另外,您可以总是将类转换为一个对象,以便能够自由访问它(但这不是一个很好的做法)。 您可能只想“将其转换为 main_maix”:

/**
 * Loader finished loading
 * 
 * @param Event Complete event
 * @return void
 */
private function onLoadMinigameComplete(event:Event):void 
{
    // -- either will allow "free access" to methods of main_maix
    var maixAsObject:Object = Object(loader.content);
    var maixAsMaix:main_maix = main_maix(loader.content);
}

main_maix looks to be the document class of the swf being loaded in. If so, main_maix should extend MovieClip instead of Sprite:

public class main_maix extends MovieClip 

Also, you can always cast classes an object to be able to access it freely (but not a very good practice). You may want to just "cast it as main_maix":

/**
 * Loader finished loading
 * 
 * @param Event Complete event
 * @return void
 */
private function onLoadMinigameComplete(event:Event):void 
{
    // -- either will allow "free access" to methods of main_maix
    var maixAsObject:Object = Object(loader.content);
    var maixAsMaix:main_maix = main_maix(loader.content);
}
小清晰的声音 2024-07-28 05:22:03

我不知道这对于动态加载的 swf 是否相同。 但是,如果您在 Flash 创作环境中制作影片剪辑,并且它只有一个帧。 然后将其嵌入到 Flex 应用程序中。 它将作为精灵而不是影片剪辑嵌入。

I don't know if this is the same for dynamically loaded swfs. But if you're making a movieclip in the Flash Authoring environment, and it only has a single frame. Then you embed that into a Flex application. It will embed as a sprite instead of a Movieclip.

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