views:

29

answers:

1

i'd like to add all or most of my mouse events to stage, but in order to do that i need to be able to tell what is the type of the sprite being clicked.

i've added two sprites to the display list, one of which is from a class called Square, the other from a class called Circle.

var mySquare:Sprite = new Square();
var myCircle:Sprite = new Circle();
addChild(mySquare);
addChild(myCircle);

now when i click on these sprites, i'd like to know from which class they are from, or which type of sprite it is.

//mousePoint returns mouse coordinates of the stage
var myArray:Array = stage.getObjectsUnderPoint(mousePoint());
if (myArray[myArray.length - 1] is Sprite)
...

so far i know how to do is determine if it IS a sprite display object, but since i'll only be working with sprites i need something more specific. rather than checking "is Sprite", is there a way i can check "is Square" or "is Circle"?

if (myArray[myArray.length - 1] is Square)
+2  A: 

You've answered your own question.

if (myArray[myArray.length - 1] is Square)

If this doesn't work, then it should, so something else is wrong.

Chris Burt-Brown
after reading the documentation, i was certain this would work. you say it should, but it continues to return as false. i don't know what possibly could be the cause of this. any ideas?
TheDarkInI1978
oh i see what my problem is. i was creating a sprite of type sprite within my class.
TheDarkInI1978