我正在进入 actionscript3,想知道是否有办法制作一个返回 id 或实例名称的“onclick”类型函数。
例如,在 jQuery 中,您可以执行以下操作,这非常适合将 id 传递到数组或您选择的任何内容中。
$('.menuButton').click(function(){
var collectedID = $(this).attr('id');
在 AS3 中是否有与此等价的功能?我假设获取实例名称将是目标?我还没有在 Flash 中遇到过 id。非常感谢大家。
我正在进入 actionscript3,想知道是否有办法制作一个返回 id 或实例名称的“onclick”类型函数。
例如,在 jQuery 中,您可以执行以下操作,这非常适合将 id 传递到数组或您选择的任何内容中。
$('.menuButton').click(function(){
var collectedID = $(this).attr('id');
在 AS3 中是否有与此等价的功能?我假设获取实例名称将是目标?我还没有在 Flash 中遇到过 id。非常感谢大家。
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 的实例名称。您很可能会将引用传递给对象。
private function clickHandler(e:MouseEvent):void
{
myArray.push(e.target);
}
addEventListener(MouseEvent.CLICK, clickHandler);