Hi all,

I am having a very odd issue with a class I made. What happens is that one
of a private variables declare in that class get overwritten when there's
more than 1 instance of that class. It seems that this var "someObject" is
common to all instances of the class. Which defites the purpose of classes.

this is a sample of the code that i am using.

import com.seb_lib.utils.Delegate;

class aclass
{
private var target:MovieClip;
private var someObject:Array = new Array();


public function aclass(target:MovieClip)
{
this.target = target
init();
}

private function init():Void
{
for (var i:Number=0; i<7; i++)
{


someObject[i] =
{
name:undefined
};

target["c"+i].onRelease = Delegate.create(this, handleClick, target["c"+i],
i);
}
}

private function handleClick(mc:MovieClip, id:Number):Void
{
for (var i:Number=0; i<7; i++)
{
trace(target +" - "+ someObject[i].name)
}

for (var i:Number=0; i<7; i++)
{
someObject[i].name = mc._name
}

for (var i:Number=0; i<7; i++)
{
trace(target +" - "+ someObject[i].name)
}
trace("**********************")
}
}


USAGE:
------------
i then create 2 instances of the class where i am passing 1 argument which
is a mc. each of these mc contains 7 buttons (could be less but the class i
am using defines 7 buttons...).

import aclass;

var d:Array = new Array()

for(var i=0; i<2; i++)
{
d.push(new aclass(this["wheel"+i]))
}



OUTPUT:
-------------
i then trace what's in the someObject before the click and after the click.
as well as this i also output the parent mc of the button which was the
argument passed in the constructor.

from the output we can conclude that someObject is sort of common for the 2
intances... this is driving me nuts...!!! how is that possible, hey?
someObject is private and also I have 2 instances of that class so i should
also have 2 intances of someObject, one for each instance....

_level0.wheel0 - undefined
_level0.wheel0 - undefined
_level0.wheel0 - undefined
_level0.wheel0 - undefined
_level0.wheel0 - undefined
_level0.wheel0 - undefined
_level0.wheel0 - undefined
_level0.wheel0 - c6
_level0.wheel0 - c6
_level0.wheel0 - c6
_level0.wheel0 - c6
_level0.wheel0 - c6
_level0.wheel0 - c6
_level0.wheel0 - c6
**********************
_level0.wheel1 - c6
_level0.wheel1 - c6
_level0.wheel1 - c6
_level0.wheel1 - c6
_level0.wheel1 - c6
_level0.wheel1 - c6
_level0.wheel1 - c6
_level0.wheel1 - c5
_level0.wheel1 - c5
_level0.wheel1 - c5
_level0.wheel1 - c5
_level0.wheel1 - c5
_level0.wheel1 - c5
_level0.wheel1 - c5
**********************

PLEASE HELP

thanks in advance

Seb
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to