Yes, you might be missed something, Jesse. I got the same result as
Muzak did.
// ActionScript 2.0
// frame action:
var instance1:MyClass = new MyClass();
var instance2:MyClass = new MyClass();
instance1.addItem("Hello World");
trace(instance1.data); // Output: Hello World
trace(instance2.data); // Output: Hello World
_____
Jesse Graupmann wrote:
Muzak,
Maybe I missed something, but instance2 in your example has no data. Only
static members can be shared across all instances - did you mean...
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Muzak
Sent: Tuesday, March 11, 2008 4:51 PM
To: Flash Coders List
Subject: Re: [Flashcoders] clean scripting
Allthough the following no longer seems to apply in AS3, it might be good to
know.
In AS2, if you have the following class:
class MyClass {
private var myArray:Array = new Array();
public function addItem(item:Object) {
myArray.push(item);
}
public function get data():Array {
return myArray;
}
}
The myArray class member will be shared across ALL instances of the class.
var instance1:MyClass = new MyClass();
var instance2:MyClass = new MyClass();
instance1.addItem("Hello World");
trace(instance1.data);
trace(instance2.data);
//output:
Hello World
Hello World
Good luck,
--
Fumio Nonaka
http://www.FumioNonaka.com/
My books<http://www.FumioNonaka.com/Books/index.html>
Flash community<http://F-site.org/>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders