AS3 Flash 从影片剪辑内的影片剪辑中调用主时间线

发布于 2024-11-30 04:13:55 字数 627 浏览 1 评论 0 原文

我在这个网站上浏览过类似的问题,但找不到解决方案,所以这是我的问题:

我有一个保存功能,可以保存一些数据。此功能位于另一个影片剪辑中的 1 个影片剪辑中。保存后我想转到主时间线的 gotoAndStop(1) 而不是当前的嵌套时间线...任何人都可以帮忙吗?

下面是代码:

function save()
{

    var oldname:String = so.data.username;
    so.data.username = oldname + tf.text + " " + nf.text + "\n";
    tf.text = "";
    nf.text = ""; // resets textfields
    so.flush(); // writes changes to disk
    trace("Saved");
    gotoAndStop(1);  <<----this must goto frame 1 of the main time line??
}

这是AS3。在AS2中我曾经能够调用_root。或_parent。本来可以正常工作,但现在它会引发编译器错误。阶段.gotoAndStop(1);也不起作用...

感谢任何帮助, 提前致谢 鲁本

I've looked through similar question on this site and can't find a solution, so here is my problem:

I have a save function that saves some data.This function is in 1 movie clip in another movie clip. After the save I want to gotoAndStop(1) of the main time line not the current nested one...can anybody help?

Below is the code:

function save()
{

    var oldname:String = so.data.username;
    so.data.username = oldname + tf.text + " " + nf.text + "\n";
    tf.text = "";
    nf.text = ""; // resets textfields
    so.flush(); // writes changes to disk
    trace("Saved");
    gotoAndStop(1);  <<----this must goto frame 1 of the main time line??
}

This is AS3. In AS2 I used to be able to call _root. or _parent. and that would work fine but now it throws a compiler error. Stage.gotoAndStop(1); also doesnt work...

Appreciate any help,
Thanks in advance
Luben

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

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

发布评论

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

评论(3

白昼 2024-12-07 04:13:55

您可以使用 DisplayObject ="nofollow noreferrer">root。由于 DisplayObject 没有 gotoAndStop() 方法,因此尝试 root.gotoAndStop() 将导致:

1061:通过静态类型 flash.display:DisplayObject 的引用调用可能未定义的方法 gotoAndStop。

但是,您可以类型转换 root MovieClip1,这将授予对其的访问权限:

MovieClip(root).gotoAndStop(1); // or:
(root as MovieClip).gotoAndStop(1);

MovieClip 的类型转换还将允许您访问主时间轴上的用户定义的属性和函数 - 这是因为MovieClip 是动态,删除了对允许访问哪些属性和方法的编译时限制 目的。


1除非您有一个继承 Sprite 而不是 MovieClip 的文档类。

You can access the topmost DisplayObject using root. Because DisplayObject does not have a gotoAndStop() method, attempting root.gotoAndStop() will result in:

1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

You can however typecast root to MovieClip1, which will grant access to it:

MovieClip(root).gotoAndStop(1); // or:
(root as MovieClip).gotoAndStop(1);

Typecasting to MovieClip will also allow you to access user-defined properties and functions on the main timeline - this is because MovieClips are dynamic which drops compile-time constraints on what properties and methods you are allowed to access on an object.


1Except for in cases where you have a document class that inherits Sprite instead of MovieClip.

箜明 2024-12-07 04:13:55

我不会在 Flash 时间轴上进行大量编码(如果您的应用程序具有中等复杂性,我建议您开始考虑通过文档根使用外部类定义);但以下建议仍然适用。

在 AS3 中,在显示列表上分派的事件可以将其 bubbles 属性设置为 true,这将启用事件冒泡。通过启用事件冒泡,您可以收听显示列表中更高的内容,以下内容文章通过您可以使用的演示很好地解释了它。

在您的应用程序中,我们假设您有两个操作“块”,即 save 函数定义和 main 函数定义:

Main

// Add an event listener, when we hear a 'SaveEvent' we will call
// the onSaveEvent function.
addEventListener("SaveEvent", onSaveEvent);

// This function is called when we hear a 'SaveEvent'.
function onSaveEvent(event : Event) : void {
    trace("Main heard event: " + event.type);

    // We can now instruct our Main Timeline.
    gotoAndStop(1);
}

Save

// Perform your save operation as before...
so.flush(); // writes changes to disk
trace("Saved");

// Now dispatch an Event, make sure we set it to bubble.
var bubbles : Boolean = true;
dispatchEvent(new Event("SaveEvent", bubbles));

I don't do a lot of coding on the Flash Timeline (and I suggest that you start looking into using external class definitions via the Document Root if your application is even of medium complexity); but the following suggest should still hold true.

In AS3, Events dispatched on the Display List can have their bubbles property set to true which will enable event bubbling. By enabling event bubbling you can listen for the even higher up on the display list, the following article does a great job of explaining it with a demo you can play with.

In your application let's assume you have two "chunks" of actions, the save function definition and the main function definition:

Main

// Add an event listener, when we hear a 'SaveEvent' we will call
// the onSaveEvent function.
addEventListener("SaveEvent", onSaveEvent);

// This function is called when we hear a 'SaveEvent'.
function onSaveEvent(event : Event) : void {
    trace("Main heard event: " + event.type);

    // We can now instruct our Main Timeline.
    gotoAndStop(1);
}

Save

// Perform your save operation as before...
so.flush(); // writes changes to disk
trace("Saved");

// Now dispatch an Event, make sure we set it to bubble.
var bubbles : Boolean = true;
dispatchEvent(new Event("SaveEvent", bubbles));
尬尬 2024-12-07 04:13:55

//因此您可以转到场景 1 的第一帧

MovieClip(root).gotoAndStop(1, "Scene 1");

//Hence you can go to the first frame of your Scene 1

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