Re: [Flashcoders] class instance and var getting overwritten
ok point noted - thx again - u saved me from making my code "dirty" any saving vars in movieclips. seb On 10/21/05, Ian Thomas <[EMAIL PROTECTED]> wrote: > > As far as I know (but haven't tested in depth, as I can't be bothered) it > only applies to Objects - i.e. Array etc. > Assignment of simple types ( var fred:Number=5 or var jim:String="test") > seems to work as expected. > > I'm not saying it _is_ a bug - I just find it odd. :-) > > Ian > > On 10/21/05, quinrou . <[EMAIL PROTECTED]> wrote: > > > > oh yes it works...!!! nice one...! > > thanks a lot for clearing this out! that doesn't make any sense... hope > MM > > will sort out this bug soon rather than later. > > > > is that true for any type of variables? Number, Boolean... > > > > seb > > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] class instance and var getting overwritten
As far as I know (but haven't tested in depth, as I can't be bothered) it only applies to Objects - i.e. Array etc. Assignment of simple types ( var fred:Number=5 or var jim:String="test") seems to work as expected. I'm not saying it _is_ a bug - I just find it odd. :-) Ian On 10/21/05, quinrou . <[EMAIL PROTECTED]> wrote: > > oh yes it works...!!! nice one...! > thanks a lot for clearing this out! that doesn't make any sense... hope MM > will sort out this bug soon rather than later. > > is that true for any type of variables? Number, Boolean... > > seb > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] class instance and var getting overwritten
oh yes it works...!!! nice one...! thanks a lot for clearing this out! that doesn't make any sense... hope MM will sort out this bug soon rather than later. is that true for any type of variables? Number, Boolean... seb On 10/21/05, Ian Thomas <[EMAIL PROTECTED]> wrote: > > Hi Seb, > If you move the new Array() call into your constructor like so: > > import com.seb_lib.utils.Delegate; > > class aclass > { > private var target:MovieClip; > private var someObject:Array; > > > public function aclass(target:MovieClip) > { > this.target = target > someObject=new Array(); > init(); > } > > ...it should work. > > It's an oddity of AS2 which I don't quite understand (seems to go against > all sense) and I've always vaguely wondered whether it's a compiler bug... > if the variable were marked 'static' it'd make sense. Oh well! > > HTH, > Ian > > On 10/21/05, quinrou . <[EMAIL PROTECTED]> wrote: > > > > 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. > > > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] class instance and var getting overwritten
Hi Seb, If you move the new Array() call into your constructor like so: import com.seb_lib.utils.Delegate; class aclass { private var target:MovieClip; private var someObject:Array; public function aclass(target:MovieClip) { this.target = target someObject=new Array(); init(); } ...it should work. It's an oddity of AS2 which I don't quite understand (seems to go against all sense) and I've always vaguely wondered whether it's a compiler bug... if the variable were marked 'static' it'd make sense. Oh well! HTH, Ian On 10/21/05, quinrou . <[EMAIL PROTECTED]> wrote: > > 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. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] class instance and var getting overwritten
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