ActionScript - clicking and determining the sprite's class
Posted
by TheDarkIn1978
on Stack Overflow
See other posts from Stack Overflow
or by TheDarkIn1978
Published on 2010-04-13T22:54:15Z
Indexed on
2010/04/13
23:03 UTC
Read the original article
Hit count: 361
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)
© Stack Overflow or respective owner