是否有一个动作脚本函数或方法来返回元素实例名称?
我正在进入 actionscript3,想知道是否有一种方法可以创建一个返回 id 或实例名称的“onclick”类型函数。
例如,在 jQuery 中,您可以执行以下操作,这对于将 id 传递到数组或您选择的任何内容中非常有用。
$('.menuButton').click(function(){
var collectedID = $(this).attr('id');
AS3中有类似的东西吗?我假设获取实例名称是目标?我还没有在Flash中遇到过id。非常感谢大家。
I'm getting into actionscript3 and was wondering if there was a way to make an 'onclick' type function that returns an id or an instance name.
For example in jQuery you can do the following, which is great for then passing the id into an array or whatever you choose.
$('.menuButton').click(function(){
var collectedID = $(this).attr('id');
Is there an equivalent to this in AS3? I'm assuming grabbing the instance name would be the goal? I haven't run across ids in Flash yet. Thanks a lot everybody.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Flash 没有元素或 id。只需调用 foo.name 即可检索实例名称。
可能最接近您想要做的事情是将 MouseEvent.CLICK 的侦听器添加到主时间线,然后添加 event.target.name。尝试一下,看看你会发现什么。
您在 jquery 中看到的精确编码风格并不真正适用于 AS3。它在 as2 中可能会工作得更好,因为 as2 比 as3 更接近 JS。
Flash doesn't have elements or ids. An instance name can be retrieved simply by callong foo.name.
Possibly the closest thing to what you want to do is add a listener for MouseEvent.CLICK to the main time line and thentrace event.target.name. play around with it and see what you find.
The precise style of coding you see in jquery doesn't really apply in AS3. It might have worked better in as2, as as2 was much closer to JS than as3.
在 AS3 中,您几乎不会使用 DisplayObject 的实例名称。您很可能会传递对该对象的引用。
In AS3 you hardly ever use the instance name of a DisplayObject. You would most likely pass the reference to the object.