[Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread Judah Frangipane
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


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread Judah Frangipane

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


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread Nathan Derksen
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


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread Judah Frangipane

Thanks for help guys!

JesterXL wrote:


Sorry, missed 1 of the traces:

// notice the array is on the prototype,
// thus all class instances point to it
foo.prototype_array.push(foo_d);
trace(foo.prototype_array);
trace(bar.prototype_array);

should be:

// notice the array is on the prototype,
// thus all class instances point to it
foo.prototype_array.push(foo_d);
trace(foo.prototype_array); // b, foo_d
trace(bar.prototype_array); // b, foo_d

- Original Message - 
From: JesterXL [EMAIL PROTECTED]

To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Thursday, December 29, 2005 3:39 PM
Subject: Re: [Flashcoders] Flash Class Array bug - Please verify


Nope, they are prototype scoped arrays, not static.

AS1:
function MyClass(){}

AS2:
class MyClass{}

AS1 - static:
MyClass.my_array = [];

AS2 - static:
class MyClass
{
   static var my_array:Array = [];
}

AS1 - prototype:
MyClass.protoytpe.my_array = [];

AS2 - prototype:
Same as above, or:
class MyClass
{
   var my_array:Array = [];
}

Prototype values, even in the class intstance, point to the prototype value
when read, but as soon as an instance modifies this value, it makes it's own
copy if it's a primitive (String, Number).  If it's an Object, it still
points to the prototype reference.  Example:

// The Class
class MyClass
{
static var static_array:Array = [a];
var prototype_array:Array = [b];
var instance_array:Array;

var prototype_name:String = MyClassName;

function MyClass()
{
 instance_array = [c];
}
}

// And here, the usages:

import MyClass;

trace(MyClass.static_array); // a
trace(MyClass.prototype.prototype_array); // b
trace(MyClass.prototype.instance_array); // undefined

var foo:MyClass = new MyClass();
trace(foo.prototype_array); // b
trace(foo.instance_array); // c

var bar:MyClass = new MyClass();
trace(bar.prototype_array); // b
trace(bar.instance_array); // c

// notice the array is on the prototype,
// thus all class instances point to it
foo.prototype_array.push(foo_d);
trace(foo.prototype_array);
trace(bar.prototype_array);

// however, for primitives, instances
// will get their own copy once they
// change it

// before
trace(foo.prototype_name); // MyClassName
trace(bar.prototype_name); // MyClassName
foo.prototype_name = MegaFoo;
// after
trace(foo.prototype_name); // MegaFoo
trace(bar.prototype_name); // MyClassName



- Original Message - 
From: Judah Frangipane [EMAIL PROTECTED]

To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Thursday, December 29, 2005 3:30 PM
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


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread ryanm

Flash is still treating the array as a static member.

   It isn't static, but it is being assigned the array object in the 
prototype, which acts sort of like a static member. You need to assign 
(initialize) it in the constructor, rather than in the member defenition.


ryanm 


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread elibol
The only response that accually addresses the problem is JesterXL's, he
seems to have hit the nail right on the head. It seems the only
differentiating aspect of static and prototype members is the way they treat
by refrence types.

On 12/29/05, JesterXL [EMAIL PROTECTED] wrote:

 Sorry, missed 1 of the traces:

 // notice the array is on the prototype,
 // thus all class instances point to it
 foo.prototype_array.push(foo_d);
 trace(foo.prototype_array);
 trace(bar.prototype_array);

 should be:

 // notice the array is on the prototype,
 // thus all class instances point to it
 foo.prototype_array.push(foo_d);
 trace(foo.prototype_array); // b, foo_d
 trace(bar.prototype_array); // b, foo_d

 - Original Message -
 From: JesterXL [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Thursday, December 29, 2005 3:39 PM
 Subject: Re: [Flashcoders] Flash Class Array bug - Please verify


 Nope, they are prototype scoped arrays, not static.

 AS1:
 function MyClass(){}

 AS2:
 class MyClass{}

 AS1 - static:
 MyClass.my_array = [];

 AS2 - static:
 class MyClass
 {
 static var my_array:Array = [];
 }

 AS1 - prototype:
 MyClass.protoytpe.my_array = [];

 AS2 - prototype:
 Same as above, or:
 class MyClass
 {
 var my_array:Array = [];
 }

 Prototype values, even in the class intstance, point to the prototype
 value
 when read, but as soon as an instance modifies this value, it makes it's
 own
 copy if it's a primitive (String, Number).  If it's an Object, it still
 points to the prototype reference.  Example:

 // The Class
 class MyClass
 {
 static var static_array:Array = [a];
 var prototype_array:Array = [b];
 var instance_array:Array;

 var prototype_name:String = MyClassName;

 function MyClass()
 {
   instance_array = [c];
 }
 }

 // And here, the usages:

 import MyClass;

 trace(MyClass.static_array); // a
 trace(MyClass.prototype.prototype_array); // b
 trace(MyClass.prototype.instance_array); // undefined

 var foo:MyClass = new MyClass();
 trace(foo.prototype_array); // b
 trace(foo.instance_array); // c

 var bar:MyClass = new MyClass();
 trace(bar.prototype_array); // b
 trace(bar.instance_array); // c

 // notice the array is on the prototype,
 // thus all class instances point to it
 foo.prototype_array.push(foo_d);
 trace(foo.prototype_array);
 trace(bar.prototype_array);

 // however, for primitives, instances
 // will get their own copy once they
 // change it

 // before
 trace(foo.prototype_name); // MyClassName
 trace(bar.prototype_name); // MyClassName
 foo.prototype_name = MegaFoo;
 // after
 trace(foo.prototype_name); // MegaFoo
 trace(bar.prototype_name); // MyClassName



 - Original Message -
 From: Judah Frangipane [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Thursday, December 29, 2005 3:30 PM
 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


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread Judah Frangipane
The thing that bothers me is that no one seems to care if this is a bug 
or not. I didnt realize that initializing an Array in the declaration 
would make a static like variable. Its not really static and it doesn't 
work the same for primitives. I spent almost 2 days going over code 
trying to solve this. I had to post it here and show it to another 
developer to pinpoint the problem. So do I report this as a bug? Do I 
announce it for others to take note of? Does it exist in AS3? Do I live 
with it until I move to AS3? Yeah, I don't know...


elibol wrote:


The only response that accually addresses the problem is JesterXL's, he
seems to have hit the nail right on the head. It seems the only
differentiating aspect of static and prototype members is the way they treat
by refrence types.

On 12/29/05, JesterXL [EMAIL PROTECTED] wrote:
 


Sorry, missed 1 of the traces:

// notice the array is on the prototype,
// thus all class instances point to it
foo.prototype_array.push(foo_d);
trace(foo.prototype_array);
trace(bar.prototype_array);

should be:

// notice the array is on the prototype,
// thus all class instances point to it
foo.prototype_array.push(foo_d);
trace(foo.prototype_array); // b, foo_d
trace(bar.prototype_array); // b, foo_d

- Original Message -
From: JesterXL [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Thursday, December 29, 2005 3:39 PM
Subject: Re: [Flashcoders] Flash Class Array bug - Please verify


Nope, they are prototype scoped arrays, not static.

AS1:
function MyClass(){}

AS2:
class MyClass{}

AS1 - static:
MyClass.my_array = [];

AS2 - static:
class MyClass
{
   static var my_array:Array = [];
}

AS1 - prototype:
MyClass.protoytpe.my_array = [];

AS2 - prototype:
Same as above, or:
class MyClass
{
   var my_array:Array = [];
}

Prototype values, even in the class intstance, point to the prototype
value
when read, but as soon as an instance modifies this value, it makes it's
own
copy if it's a primitive (String, Number).  If it's an Object, it still
points to the prototype reference.  Example:

// The Class
class MyClass
{
static var static_array:Array = [a];
var prototype_array:Array = [b];
var instance_array:Array;

var prototype_name:String = MyClassName;

function MyClass()
{
 instance_array = [c];
}
}

// And here, the usages:

import MyClass;

trace(MyClass.static_array); // a
trace(MyClass.prototype.prototype_array); // b
trace(MyClass.prototype.instance_array); // undefined

var foo:MyClass = new MyClass();
trace(foo.prototype_array); // b
trace(foo.instance_array); // c

var bar:MyClass = new MyClass();
trace(bar.prototype_array); // b
trace(bar.instance_array); // c

// notice the array is on the prototype,
// thus all class instances point to it
foo.prototype_array.push(foo_d);
trace(foo.prototype_array);
trace(bar.prototype_array);

// however, for primitives, instances
// will get their own copy once they
// change it

// before
trace(foo.prototype_name); // MyClassName
trace(bar.prototype_name); // MyClassName
foo.prototype_name = MegaFoo;
// after
trace(foo.prototype_name); // MegaFoo
trace(bar.prototype_name); // MyClassName



- Original Message -
From: Judah Frangipane [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Thursday, December 29, 2005 3:30 PM
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



 



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Flash Class Array bug - Please verify

2005-12-29 Thread ryanm
The thing that bothers me is that no one seems to care if this is a bug or 
not.


   It shouldn't, it's been discussed at least a hundred times here already, 
and it's not a bug. Don't initialize class variables in the class 
defenition, it adds them to the prototype. Initialize them in the 
constructor and everything will work exactly how you expect it to.


ryanm 


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders