Yes, when you assign an initial value to a property, it is basically
like a static assignment. Do the initialization in the constructor
instead. This works for me:
class myClass
{
// initialize the array in the declarations
var myArray:Array;
function myClass()
{
myArray = new Array()
trace("myArray.length="+myArray.length)
}
function addToArray()
{
myArray.push(10)
}
}
Nathan
http://www.nathanderksen.com
On Dec 29, 2005, at 12:48 PM, Judah Frangipane wrote:
Hi Glenn,
Flash is still treating the array as a static member.
// treated as an instance variable
var myArray1:Array;
// treated as a static variable
var myArray2:Array = new Array();
Test this code:
// in actions frame 1
import myClass
trace("Creating instance a")
var a = new myClass();
a.addToArray();
a.addToArray();
a.addToArray();
trace("Creating instance b")
var b = new myClass();
// in class
class myClass {
// treated as an instance variable
var myArray1:Array;
// treated as a static variable
var myArray2:Array = new Array();
static var myArray3:Array = new Array();
function myClass() {
trace(" myArray1.length="+myArray1.length)
trace(" myArray2.length="+myArray2.length)
trace(" myArray3.length="+myArray3.length)
}
function addToArray() {
myArray1.push(10);
myArray2.push(10);
myArray3.push(10);
}
}
Glenn J. Miller wrote:
Hey Judah,
Try this:
class myClass {
// initialize the array in the declarations
private var myArray:Array = new Array();
function myClass {
trace("myArray.length="+this.myArray.length)
}
public function addToArray() {
this.myArray.push(10);
this.myArray.push(20);
}
} // end class
Run your code again, I think it'll execute the way you're
expecting it to at
that point...
Peace...
--
Dok
Skyymap, Inc.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Judah
Frangipane
Sent: Thursday, December 29, 2005 3:30 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Flash Class Array bug - Please verify
It seems like Flash is creating static members out of public
arrays that are initialized in the class declaration. Can someone
confirm this? Is this not legal, is it implied behavior or a bug?
// create a class called myClass
class myClass {
// initialize the array in the declarations
var myArray:Array = new Array();
function myClass {
trace("myArray.length="+myArray.length)
}
function addToArray() {
myArray.push(10)
myArray.push(20)
}
}
// on the actions frame
import myClass
var a = new myClass();
a.addToArray();
a.addToArray();
a.addToArray();
var b = new myClass();
// trace outputs
myArray.length=0
myArray.length=3
Judah
_______________________________________________
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
_______________________________________________
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