访问影片剪辑变量
如何从其父级访问影片剪辑变量?我已经尝试了几种不同的方法但仍然失败。
How can i access a movie clip variable from its parent? I have done tried several different ways but still failed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MovieClip 是一个动态对象,因此如果您要在影片剪辑上动态设置属性,或者即使您想访问内置属性或方法,您只需通过直接从父级引用子级即可实现。就像这样:
基本上在 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:
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.
如果您只是想访问舞台上存在的影片剪辑,请在属性面板中为其指定一个实例名称,然后您可以使用 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