简体   繁体   中英

ActionScript - clicking and determining the sprite's class

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM