ActionScript 3.0 :: Different Between Instanceof And __proto__?
Jan 30, 2010while trying oop the inheritance and not the composition way I tried two different ways to find out whether an object ( lets say circleclip1 which is a Movieclip in library with an identifier provided )formed from a class (lets say circleDemo)which extends MovieClip is truly an instance of that class.
I use the trace(circleclip1.__proto__==circleDemo.prototype) to check the same it outputs true in the trace window as it should.but when I use the instanceof operator it would return true no matter whichever ancestor I use to check it against the object instance..eg
trace(circleclip1 instanceof circleDemo);// yields "true"
trace(circleclip1 instanceof MovieClip);// checking against Movieclip yields "true"
trace(circleclip1 instanceof Object);// checking against top level Object yields "true"
Now my question is why does this instanceof operator return true for any ancestor up the inheritance chain uptill the top level object.while when I use
trace(circleclip1.__proto__==MovieClip.prototype);// yields "false"
so the verification implies circleclip1 is not directly an instance of MovieClip since it has been subclassed through circleDemo hence the output false.how would I test whether in as3.0 circleclip1 is truly an instance of circleDemo.because instanceof operator keeps yielding the same result as as2.0 and frustratingly enough that __proto__ property of any object is not around any more in as3.0.
I have attached two .zip files of as2.0 and as3.0 version containing the demonstration of the problem queried above respectively, as printing all the lines from those files here in this post would clutter up the area.