在闪光灯AS3.0,我不得不从一个动画片段呼吁主舞台的函数闪光灯、函数、片段、舞台

由网友(临时心动)分享简介:我必须调用在我的项目的主要阶段定义的函数,而我也从一个影片剪辑调用它,我该怎么办?我使用闪光灯CS5.5和AS3.0 I have to call a function that is defined on the main stage of my project, and I have to call it fr...

我必须调用在我的项目的主要阶段定义的函数,而我也从一个影片剪辑调用它,我该怎么办? 我使用闪光灯CS5.5和AS3.0

I have to call a function that is defined on the main stage of my project, and I have to call it from a MovieClip, what can I do? I'm using flash cs5.5 and AS3.0

推荐答案

有多种方法可以从对象访问MainTimeline在舞台上。也许最可靠的是根,但也有父(但只有当你是影片剪辑在主时间轴的直接子)。

There are multiple ways to access the MainTimeline from objects on the stage. Probably the most reliable is 'root', but there is also 'parent' (but only if you MovieClip is a direct child of the main timeline).

// root should always work
Object(root).myFunc();

// parent will only work if your movieclip is a direct child of the main timeline
Object(parent).myFunc();

请注意,您必须转换这些都是通用的对象(或MovieClip将工作),因为他们返回没有myFunc的功能在这些类型的类。

Note that you have to cast these are generic Objects (or MovieClip would work) because they return typed classes that don't have a 'myFunc' function in them.

您将需要您的主时间轴上的这个code:

You'll need this code on your main timeline:

function myFunc():void {
  trace("My function got called!");
}
阅读全文

相关推荐

最新文章