如何获取动态创建的Flash舞台上MovieClip的名称?
有多个影片剪辑将动态放置在舞台上。这些影片剪辑被编码为按钮。我试图弄清楚——当用户单击 MovieClip 时...找出用户单击了 Flash 舞台上的哪个对象。
在函数toggleClick 内部,我放置了跟踪语句:
trace("movieClip Instance Name = " + e.target.name);
在输出窗口中:
movieClip Instance Name = instance5
movieClip Instance Name = instance12
movieClip Instance Name = instance5
movieClip Instance Name = instance32
movieClip Instance Name = instance5
movieClip Instance Name = instance59
这似乎不是获取所单击的MovieClip 名称的方法。
getChildByName() 是这样做的方法吗?如果是这样,有什么想法如何使用 getChildByName() 来获取单击的 MovieClip 的名称吗?
There are multiple MovieClips that will be dynamically placed on stage. These MovieClips are coded to be buttons. I'm trying to figure out--when a user clicks on the MovieClip...figure out which object on the flash stage the user clicked on.
Inside function toggleClick I put the trace statement:
trace("movieClip Instance Name = " + e.target.name);
In the OUTPUT window:
movieClip Instance Name = instance5
movieClip Instance Name = instance12
movieClip Instance Name = instance5
movieClip Instance Name = instance32
movieClip Instance Name = instance5
movieClip Instance Name = instance59
That doesn't seem the way to get a name for the MovieClip that was clicked.
Is getChildByName() the way to do it? If so, any ideas how to use getChildByName() to get the name of the MovieClip that was clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将按钮添加到舞台之前,您可以实际命名它
,或者
通过您的示例,您可以执行以下操作:
Before adding a button to the stage you can actually name it
or
With your example you could do something like this:
在 AS3 中,当您动态创建 MovieClip 时,Flash 会为其分配一个只读实例名称,如您所见(例如,instance12)。查找哪个影片剪辑被单击的最佳方法是简单地使用 MouseEvent 的 currentTarget/target (请在此处查看两者之间的区别:http://www.wastedpotial.com/?p=10)。
你会像这样使用它:
In AS3 when you create a MovieClip dynamically flash asigns it a read-only instance name like you have seen (instance12 for example). The best way to find which movieclip was clicked on is to simply use the currentTarget/target of the MouseEvent (see the difference between the two here: http://www.wastedpotential.com/?p=10).
You would use it like so: