如何导入文档类文件并在框架上播放它

发布于 2024-10-27 23:27:16 字数 112 浏览 3 评论 0原文

我有 2 个 Flash 文件,一个带有简介,第二个只有一个可以玩贪吃蛇游戏的文档类文件。我如何导入该文档 Flash 文件并使其在其他 Flash 文件的第 100 帧上播放。

谢谢你的帮助。

I have 2 flash files, one with an intro and the second that just has a document class file that plays out a snake game. How could i import that document flash file and make it play out on like frame 100 off my other flash file.

Thankyou for any help.

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

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

发布评论

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

评论(1

妞丶爷亲个 2024-11-03 23:27:16

您可以在介绍中实例化 Snake 类文件,在第 100 帧上使用如下代码:

var game:Snake = new Snake();
addChild(game);

假设您的文档类名为 SnakeGame。不过,您可能需要在 SnakeGame 中进行一些更改才能使其正常工作。使用此方法时,SnakeGamestageroot 属性在构造函数中将为 null。这与文档类(或直接放置在舞台上)的行为不同 - stageroot 已经初始化。因此,如果您在构造函数中对 rootstage 执行任何操作,则必须更改此设置,否则将收到错误。要解决此问题,请侦听 Snake 中的 ADDED_TO_STAGE 事件:

public function Snake() {
    addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

public function onAddedToStage(event:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    // stage+root are now valid, put your init code here
}

或者,您可以将 Snake 类链接到空的 MovieClip 元件并将其直接放置在舞台上第 100 帧上。首先,通过转到“窗口”->“库”并单击“+”来创建一个空的影片剪辑。在“创建新符号”对话框中,选中“导出为 ActionScript”,然后在“链接”下的“类”字段中输入 Snake。现在,您可以将该 MovieClip 直接拖到舞台上的第 100 帧上,希望它无需更改代码即可正常工作。

You can instantiate the Snake class file in your intro, using code like the following on frame 100:

var game:Snake = new Snake();
addChild(game);

assuming your document class is called SnakeGame. You may have to make a few changes in SnakeGame for this to work, however. The stage and root properties of SnakeGame will be null in the constructor when using this method. This is different behavior from it's was the document class (or placed directly on the stage) -- stage and root are already initialized. So if you do any actions to either root or stage in the constructor, you must change this or you will get an error. To fix this, listen for the ADDED_TO_STAGE event in Snake:

public function Snake() {
    addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

public function onAddedToStage(event:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    // stage+root are now valid, put your init code here
}

Alterantively, you could link the Snake class to an empty MovieClip symbol and place that directly on the stage on frame 100. First, create an empty MovieClip by going to Window->Library and clicking the +. In the Create New Symbol dialog, check "Export for ActionScript" and type in Snake in the Class field under Linkage. Now you can drag that MovieClip directly onto the stage on frame 100 and it hopefully will work without changes to the code.

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