all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

AS 2.0 class instantiation problems


Re: AS 2.0 class instantiation problems David Stiller
4/1/2005 3:32:08 PM
flash actionscript:
wjmp,

[quoted text, click to view]

Very odd.

[quoted text, click to view]

Exactly as you've done. I do it all the time.

[quoted text, click to view]

Well enough .. but there must be something you haven't mentioned.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

AS 2.0 class instantiation problems wjmp
4/1/2005 7:55:18 PM
I'm working with 2.0 classes and I'm having a hard time getting 2 instances of
the same class to work independently of each other. I'm dealing with 1000s of
lines of code so a copy/paste is beyond the scope of this question. Basically
what is happening is that the second instantiation ends up overwriting the
first instantiation. For example: var myObj1:myClass = new myClass ( 'Tom' ,
'Dick' , 'Jane'); var myObj2 : myClass = new myClass ( 'Fred', 'Steve',
'Sally'); myObj2 overwrites the myObj1 instance. How can I instantiate 2
objects of the same class without one destroying the other? Other notes: -
all class variables are private - the class also uses the WebServices class -
class objects are defined in different MC's on different levels Hope I've
explained my problem well. Any help would be much appreciated. wp
Re: AS 2.0 class instantiation problems Jeckyl
4/2/2005 7:33:28 AM
You are probably creating your array when you define the variable, instead
of in the constructor. If you do it where the variable is defined, the
array is shared. eg

bad:

class MyClass {
var myarry : Array = new Array;
function MyClass() {
}
}

good:

class MyClass {
var myarry : Array;
function MyClass() {
myarry = new Array;
}
}

--
Jeckyl

AddThis Social Bookmark Button