  | |  | Array property of MoveClip subclass problem | Array property of MoveClip subclass problem 2004-03-12 - By Pranav Verma
Back Hi Ingo, check this!
class testClass extends MovieClip { // properties: var test:Array = new Array(); // constructor: function testClass() { test=[]; test.push("hi"); onRollOver = function(){trace(test)}; } } Now EXPLANATION...
I am not an expert with other OOP languages but as far as AS is concern , multiple instances of an Array object always always refer to one array only. so...
a= []; b=[]; b =a; b.push("junk");
this will add the "junk" in array 'b'.... array 'b' will be blank, ya if you talk of Number string then it's ok . the moment you created a new var.. new reference is created.
so in case of array u need to define the array inside the constructor so that the flash compiler will create diff. refrence for each array objects. otherwise all array object will refer to one ref only...( thats why in ur example the array was appending itself on each push )
I hope it all make sense.... please revert back with queries if any.
HTH, Pranav
> -- --Original Message-- -- > From: Ingo Weiss [mailto:ingo01@(protected)] > Sent: Friday, March 12, 2004 11:42 AM > To: flashcoders@(protected) > Subject: [Flashcoders] Array property of MoveClip subclass problem > > > I am having a strange problem that I finally narrowed down to > this: > > In a movieClip subclass, I have a property "test" of type Array: > > > class testClass extends MovieClip { > > // properties: > var test:Array = new Array(); > > // constructor: > function testClass() { > test.push("hi"); > onRollOver = function(){trace(test)}; > } > > } > > > > Now if I place 3 instances of the clip on the stage, first of all > "test" doesn't show up in the Debugger's "variables" pane (why?). > Then, I would expect the "test" of each instance to have one > member, "hi". Instead, they have 3 (one for each instance, ["hi", > "hi", "hi"])? it's as if the instances would share one property > "test". Why is that? > > Thanks for any help!! > Ingo > > =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- > -- ------ > Supported by Fig Leaf Software > =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- > -- ------ > Be sure to check the archives and the wiki: > http://chattyfig.figleaf.com/ > =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- > -- ------ > http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:106718 > =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- > -- ------ > To unsubscribe send a blank e-mail to: > Normal Mode: flashcoders-unsubscribe@(protected) > Digest Mode: flashcoders-digest-unsubscrive@(protected) >
**************************************************************************** This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Visit us @ http://www.masconit.com ****************************************************************************
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Supported by Fig Leaf Software =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/ =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:106720 =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe send a blank e-mail to: Normal Mode: flashcoders-unsubscribe@(protected) Digest Mode: flashcoders-digest-unsubscrive@(protected)
Earn $52 per hosting referral at Lunarpages.
|
|
 |