访问影片剪辑变量

发布于 2024-11-01 21:00:54 字数 41 浏览 2 评论 0原文

如何从其父级访问影片剪辑变量?我已经尝试了几种不同的方法但仍然失败。

How can i access a movie clip variable from its parent? I have done tried several different ways but still failed.

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

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

发布评论

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

评论(2

爱她像谁 2024-11-08 21:00:54

MovieClip 是一个动态对象,因此如果您要在影片剪辑上动态设置属性,或者即使您想访问内置属性或方法,您只需通过直接从父级引用子级即可实现。就像这样:

var myMovie:MovieClip = this.myChildMovie;

trace(myMovie.myProperty);

myMovie.myProperty = 7;

trace(myMovie.myProperty);

基本上在 AS3 中,我们有一个适当的显示列表,我们通过用于遍历显示列表的特定方法来访问子项和父项。在 as2 中,基本上新的显示对象成为其父对象的动态属性。因此,您只需将它们作为属性直接访问即可。但请注意,AS2 和 AS1 在范围方面存在很大问题。使用术语“此”可能会根据您使用它的位置而变化。这是一个上下文相关的术语。范围也很容易丢失/混淆,尤其是在 AS1 中。例如,如果您输入一个作为属性附加到剪辑的函数,在该函数的顶层,说“this”将引用该函数对象(我相信,自 1/2 天以来已经很长一段时间了)。但是,如果您要在该函数内创建一个 LoadVars 对象,并输入该 LoadVars 对象的回调方法,则范围会再次更改,从而“this”的上下文也会更改。我知道这可能非常令人困惑,但是当你仔细考虑一下就会明白。我建议学习 AS3,一开始你会讨厌它,但后来会想如果没有它你会如何相处。

无论如何,这堂课的简短版本是:确保当您尝试引用这个孩子时,您是在正确的范围内进行的。如果您对 Flash 非常陌生,请访问此网站:

http://gotoandlearn.com/

AS2 教程就在后面几页,但是,该网站应该拥有让您坚定地使用 Flash 所需的一切。

MovieClip is a dynamic object so if you're setting a property dynamically on a movieclip or even if you want to access a builtin property or method you simply do so by directly referencing the child from the parent. Like so:

var myMovie:MovieClip = this.myChildMovie;

trace(myMovie.myProperty);

myMovie.myProperty = 7;

trace(myMovie.myProperty);

Basically in AS3 we have a proper display list, where we access children and parents through specific methods used to traverse the display list. In as2, basically new display objects become a dynamic property of their parent. So you just access them directly as a property. Note however that AS2 and AS1 have big issues with scope. Using the term "this" is subject to change depending on where you are using it. It is a context-sensitive term. Also scope can become easily lost/confused, especially in AS1. For example if you enter a function attached as a property to a clip, in the top level of that function, saying "this" will reference the function object (I believe, it's been a LONG time since as1/2 days). However, if you were to create lets say a LoadVars object inside that function, and enter the callback method of that LoadVars object, the scope changes again and thus the context of "this". I know that's probably pretty damn confusing, but you'll see as you mull it over. I advise learning AS3, you'll hate it at first but then wonder how you ever got along without it.

Anyway so short version of the lesson: ensure that when you are trying to reference this child, that you are doing it in the proper scope. If you are very new to flash all together, check out this website:

http://gotoandlearn.com/

The AS2 tutorials are a few pages back but, that website should have everything you need to get you firmly on your feet with flash.

梅倚清风 2024-11-08 21:00:54

如果您只是想访问舞台上存在的影片剪辑,请在属性面板中为其指定一个实例名称,然后您可以使用 myMovieclip.variable 访问该变量。

如果您使用 as2 进行编程,请查看 http://www.kirupa.com/developer /oop2/AS2OOPindex.htm

If you are just looking to access a movieclip that exists on the stage, give it an instance name in the property panel, then you can access the variable with myMovieclip.variable.

If you are programming with as2, then check out http://www.kirupa.com/developer/oop2/AS2OOPindex.htm

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