Found this interesting. I've gotten used to checking object type, as run time. So, when I tried to figure out how to do it in AS3, I was surprised at some fairly convoluted approaches out there. Happily, the AS3 documentation came through, and I tried this out. Works like a charm, for my purposes.
function mouseOverListener(event:MouseEvent):void {
var targ = event.target;
trace("this: " + targ); // output is "[object Infopop]"
trace("type: " + targ.constructor); // output is "[class Infopop]"
if(targ.constructor == InfoPop){
trace("infopop");
}
}
For type checking, I want the constructor, not the object.
Update: Read the first comment on this post: very helpful!
Saturday, February 26, 2011
Subscribe to:
Post Comments (Atom)


5 comments:
How about this:
if( event.target is InfoPop )
Cheers, Balazs
if(event.target is InfoPop){
--> works
if(event.target.constructor is InfoPop){
--> doesn't work
if(event.target.constructor == InfoPop){
--> works
Interesting. Nice to have options.
Honestly, there is endless fascination in code. So many ways to accomplish the same goal. I love it!
and from a performance point of view, which syntax to choose?
Post a Comment