ActionScript 3.0 :: Different Between Instanceof And __proto__?

Jan 30, 2010

while 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.

View 3 Replies


Similar Posts:


ActionScript 2.0 :: __proto__ - Assign A Class To Each Object In Function Of An Array?

Sep 25, 2007

I'll try to make this as clear as possible. Let's say i have 4 "classes".

[Code]...

Let's say now i use a loop to create 8 obj. I'd like to assign a class to each obj in function of an array like : array = [class1, class2, class1, class3, class2, class4... ] so obj0 class' should be array[0]

View 4 Replies

Actionscript 3 :: Instanceof For Dynamic Interface?

Mar 8, 2010

interface If { ... }
class Impl implements If { ... }
function test(type:Class, obj) {
return obj instanceof type;
}
test(If, new Impl());

The call to test on the last line returns false, but it should be true. How can I do this check right, with the requirement that it must be inside the function?

Real code:

public function iterate(callback:Function, type:Class = null) {
for (var node:EntityListNode = beginNode; node != null; node = node.next) {
if (type == null || node.entity instanceof type) callback(node.entity);
}
}

View 1 Replies

Flex :: Mxml Inheritance Works Instanceof?

Jul 5, 2010

[Code]....

It is not works! When I see in debugger, child have type "Screen2", but "child is Screen" returns false to me (and "child instanceof Screen" too). When I apply compiler key: "-keep-generated-actionscript" I can see Screen2-generated.as and it's contains public class Screen3 extends screens.Screen

View 1 Replies

Actionscript 3 :: Applying The Is Operand Or The Instanceof In A Case Statement?

Dec 30, 2009

I am trying to figure out how to apply the is operand or the instanceof in a case statement to determine which datatype a interface object belongs too. keep getting errors

switch (IOjbect is)
{
case Tile:

[code].....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved