Search code examples
actionscript-3instances

is there an actionscript function or method to return an elements instance name?


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.


Solution

  • 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.