[OOP] tracing instances of Class

myClass = function(name) {
	this.name=name
}

instance1 = new myClass("a")
instance2 = new myClass("b")
instance3 = new myClass("c")

trace(instance1 instanceof myClass)
trace("
")

for (var i in _root) {
	trace(i instanceof myClass) 
}

outputs

true


false
false
false
false
false

this’s been bugging me, anyone know what’s wrong? ;(

I realize this isn’t what you want, but if I do this, then it outputs fine:


myClass = function (name) {
	this.name = name;
};
instance1 = new myClass ("a");
instance2 = new myClass ("b");
instance3 = new myClass ("c");
trace (instance1 instanceof myClass);
trace ("
");
for (i = 1; i <= 3; i++) {
	ext = _root["instance" + i];
	trace (ext instanceof myClass);
}

what does the


for(var i in _root)

do and where does it come from? i is never defined. does that matter? I dunno…

[AS]myClass = function (name) {
this.name = name;
};
instance1 = new myClass(“a”);
instance2 = new myClass(“b”);
instance3 = new myClass(“c”);
trace(instance1 instanceof myClass);
trace("
");
for (var i in _root) {
trace(_root* instanceof myClass);
}[/AS]

:beam:

oh, and I have you on my buddy list, but you’re never online… are you avoiding me?

Jubba: It is called a for/in loop, they can be quite useful sometimes.

http://www.kirupa.com/developer/actionscript/tricks/forin.asp

that makes sense lost…

*Originally posted by Jubba *
**oh, and I have you on my buddy list, but you’re never online… are you avoiding me? **

Who? Me? Or Ahmed?

:beam:

that’s great, how could i miss that :stuck_out_tongue: :love:

jubs-
that would work too, only thing is, their names arent gonna be uniform :slight_smile:

ahmed :slight_smile:

Hmm, weird, I start with a new document, use this code…

[AS]myClass = function (name) {
this.name = name;
};
instance1 = new myClass(“a”);
instance2 = new myClass(“b”);
instance3 = new myClass(“c”);
for (var i in _root) {
trace(_root* instanceof myClass);
trace(_root*.name);
}[/AS]

And I get 2 extra undefined objects :q: I don’t get it.

if me, I changed sn’s :stuck_out_tongue:

mine now is synOrange :beam:

I know nothing about AS in Flash anymore.

and you didn’t answer my question :stuck_out_tongue:

*Originally posted by lostinbeta *
**And I get 2 extra undefined objects :q: I don’t get it. **

for (var i in _root) {
        trace(_root*);
}

:wink:

edit:

the second one is ‘myClass’, and then comes the three instances of it, totals up to 5 :slight_smile:

*Originally posted by Jubba *
**I know nothing about AS in Flash anymore. **

You lie.

  • myClass
  • $version

An if statment would sort it out.

*Originally posted by ahmed *
**

for (var i in _root) {
        trace(_root*);
}

:wink:

edit:

the second one is ‘myClass’, and then comes the three instances of it, totals up to 5 :slight_smile: **

OMFG I knew that too… it totally friggin skipped my mind…lol.

*Originally posted by h88 *
**- myClass

  • $version

An if statment would sort it out. **

Surely would…

[AS]myClass = function (name) {
this.name = name;
};
instance1 = new myClass(“a”);
instance2 = new myClass(“b”);
instance3 = new myClass(“c”);
for (var i in _root) {
if (_root* instanceof myClass) {
trace(_root*.name);
}
}[/AS]

confuzzled… :frowning:

oh and Ahmed, mine is --------- :slight_smile:

*Originally posted by Jubba *
**confuzzled… :frowning:

oh and Ahmed, mine is ------- :slight_smile: **

:frowning:

[AS]
//constructor function to make new object
myClass = function (name) {
this.name = name;
};
//make new object with name “a”, etc, etc.
instance1 = new myClass(“a”);
instance2 = new myClass(“b”);
instance3 = new myClass(“c”);
//use for in loop to cycle through objects on the _root timeline
for (var i in _root) {
//if the object found is an instance of the myClass object
if (_root* instanceof myClass) {
//trace it’s name variable
trace(_root*.name);
}
}
[/AS]

Any help?

oh I get it, I just don’t see how it would do me any good with my scripting. I need to brush up, but I never have any time :frowning: