在as3.0的flash中,我必须从movieClip调用主舞台上的一个函数 [英] In flash with as3.0, I have to call a function on the main stage from a movieClip

查看:24
本文介绍了在as3.0的flash中,我必须从movieClip调用主舞台上的一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须调用在项目主阶段定义的函数,并且必须从 MovieClip 中调用它,我该怎么办?我使用的是 flash 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.可能最可靠的是根",但也有父"(但前提是您的 MovieClip 是主时间线的直接子项).

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.

您需要在主时间线上使用此代码:

You'll need this code on your main timeline:

function myFunc():void {
  trace("My function got called!");
}

这篇关于在as3.0的flash中,我必须从movieClip调用主舞台上的一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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