Background Information:
- I am using Adobe Flash CS4
- I am using Actionscript 3
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.
- I'm using "getObjectsUnderPoint" to detect the objects under where the mouse is clicked.
- I have verified that getObjectsUnderPoint is detecting the symbol instances by tracing the names.
The Problem
- The traced names of the objects detected by getObjectsUnderPoint are all instance1, instance2, instance3, etc. even though I have named the instances.
- This causes an issue when trying to ensure that the mouse was clicked on a zone encompassed by either one of the rectangles, as I can't check if object[i].name == "leftbox" , and the instance1, instance2, etc. names change as I add/remove things from the stage, so I do not want to check for instance2 and instance3 (which are as of right now the 2 boxes I've created, which are named "leftbox" and "rightbox" respectively.
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;
}