# "For...in" inside classes (AS2.0)

**URL:** <https://forum.kirupa.com/t/for-in-inside-classes-as2-0/251398>\
**Category:** flash\
**Created:** [February 8, 2008, 1:02am UTC](https://forum.kirupa.com/t/for-in-inside-classes-as2-0/251398 "2008-02-08T01:02:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nacritico](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nacritico](https://forum.kirupa.com/u/nacritico)\
**Post date:** [February 8, 2008, 1:02am UTC](https://forum.kirupa.com/t/for-in-inside-classes-as2-0/251398/1 "2008-02-08T01:02:56Z")

</div>

Well, this is something I’ve been wondering this since 5 months ago when I started using classes on AS 2.0 .  
I’ve already asked this on other forum, but without help of anyone (because nobody knew), so here I’m quoting it:

> [@"nacritico"](#):
>
> I’ve this problem. I’m programing a class in order to make movement in my characters. Well the thing is that I need to make this work
> 
> ```auto
> 
> public function isBeingHitted():Boolean{
> for(z in _root.badies){
> trace(z)
> if(this.hitTest(_root.badies[z])){
> return true
> }
> }
> return false
> }
> 
> ```
> 
> for some “unknown” reason, when it trace z, instend of tracing the objects and properties of _\_root.badies_, it traces all _undefined_.
> 
> The weird thing is that if I put this on \_root :
> 
> ```auto
> 
> _root.onEnterFrame = function(){
> for(z in _root.badies){
> trace(z)
> }
> }
> 
> ```
> 
> it works… THEN WHY DOES NOT IT WORK INSIDE THE CLASS??

the thing is that I found no usefull solution in this (Wheter I use “for…in” inside a class, it always returns “undefined” :(). The only thing I could came up with was this:

> [@"nacritico"](#):
>
> Well, it seems that this overpassed X2i or that he was too lazy to help me.  
> Anyway, here is the “patch” I found to this problem (in fact, is something a bit wrong… but is the best way to use “for…in” inside the 2.0 action script).
> 
> Well, the thing is to do this inside the class:
> 
> ```auto
> 
> class character extends MovieClip{
> function classFor(){
> }
> }
> 
> ```
> 
> and then add this to the main movie:
> 
> ```auto
> 
> character.prototype.classFor = function(url){
> stuff= []
> for(z in url){
> if(url[z] instance of MovieClip){
> stuff.push(url[z])
> }
> }
> return stuff
> }
> 
> ```

And I’m very unhappy with it ☹ … can anyone tell me a better solution?

salu2’2
