Background Information:
I am publishing my code into an Adobe AIR document, however I am not sure that this is relevant to this particular problem.
I've created two symbols in the library, large rectangles, and placed instances of them on the stage.
The Problem
The Question:
Am I doing something wrong in detecting the names? How do I actually detect the instance names that I have created on the stage through the ActionScript in my class?
Here is my code:
var pt:Point = new Point(e.stageX, e.stageY);
var objects:Array = getObjectsUnderPoint(pt);
var action = 0;
for(var i=0; i< objects.length; i++) {
trace(objects[i].name);
}
if( objects.indexOf('left_box') >= 0 ){
action = 1;
}
if(objects.indexOf('right_box') >= 0 ){
action = 2;
}
Taking forward Fahim Akhter's answer,
You can then loop to get the parent until the object is a movieclip
var o:DisplayObject=objects[i];
while(!(o.parent is MovieClip)) {
o=o.parent;
}
var myMovieClip:MovieClip=o.parent;
This should give you a movie clip in myMovieClip and when you trace myMovieClip.name
, you'll get what you are looking for.
This will also work for multiple level symbols (where 1 symbol contains another)