加载SWF为ActionScript 3的项目(Flex Builder中) [英] Loading a SWF into an ActionScript 3 project (Flex Builder)

查看:193
本文介绍了加载SWF为ActionScript 3的项目(Flex Builder中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个小的Flash gamelet为我们的欧洲客户,谁要求我们开发这样的方式我们的Flash游戏,他们可以载入我们的SWF游戏到他们的ActionScript 3的项目,动态的。

We're developing a small Flash gamelet for an European client of ours, who require us to develop our Flash game in such fashion that they can load our SWF game into their ActionScript 3 project, dynamically.

基本上他们有一个控制台,会加载很多其他的Flash游戏,我们自己之间,这取决于哪个按钮上的选择您的游戏的玩家presses屏幕。

Basically they have a console that will load many other Flash games, amongst our own, depending on which button the player presses on a "Choose Your Game" screen.

基本上,我们有我们创作在Flash Professional CS4一个FLA项目,一切基本上是一个简单的Flash游戏。当我们测试游戏,通过按Ctrl + Enter或运行通过双击编译SWF文件单击它,一切运作良好,游戏中完美的执行,每个人都是幸福的兔子。

Basically, we have a FLA project that we're authoring in Flash Professional CS4 and everything is basically a straightforward Flash game. When we test the game via Ctrl+Enter or run the compiled SWF file by double clicking it, all works well, the game executes perfectly and everybody is a happy bunny.

我们需要把握的是加载我们的SWF到我们的客户AS3的项目,基本上是在Flex Builder 3的客户端发布我们以下code加载SWF创建的外部ActionScript 3的项目:

What we need to grasp is loading our SWF into our clients AS3 project, which is basically an external ActionScript 3 project created in Flex Builder 3. The client posted us the following code to load the SWF:

var myGame:FunkyChickenGame = new FunkyChickenGame();
addChild(myGame);

...它获取客户端的ActionScript 3的应用程序构造应用程序执行的,或者可能是事件处理程序pssed上的按钮$ P $选择您的游戏的画面。

...which gets executed in the ActionScript 3 application constructor of the clients app, or perhaps an event handler for a button pressed on the "Choose Your Game" screen.

我们尝试创建在Flex Builder空白AS3项目,并尝试加载的SWF按我上面的代码段。外部SWF的文件类中我们所有的痕迹都显示为预计的Flex Builder控制台视图,因此code完美运行。

We tried creating a blank AS3 project in Flex Builder and tried loading the SWF as per my snippet above. All our traces within the external SWF's document class are showing up as expected in the Flex Builder console view, so the code is running perfectly.

我们遇到的问题是,尽管调用addChild(myGame)......我们没有看到任何图形,封装AS3项目只是默认背景色。

The problem we're experiencing is that despite calling addChild(myGame)...we're not seeing any graphics, just the default background color of the encapsulating AS3 project.

请注意然而,当我们双击Windows中的Game.swf文件运行的SWF,这一切都完美地执行,游戏作品,未经缺陷和故障。

Note however, when we run the SWF by double clicking the Game.swf file in Windows, it all executes perfectly, the game works without flaw and glitches.

有关此主题的任何帮助将是非常美联社preciated。谢谢你在前进。

Any help on this topic would be highly appreciated. Thank you in advance.

推荐答案

您需要使用什么是Loader类的一个实例,像这样:

What you need to use is an instance of the Loader class, like so:

var loader:Loader = new Loader();

// you'll need to write a method named onLoaded to capture the COMPLETE event
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);

loader.load(new URLRequest("game.swf"));
addChild(loader);

这篇关于加载SWF为ActionScript 3的项目(Flex Builder中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆