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


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

2005-12-29 Thread JesterXL
It is not a bug, it is the way ActionScript & JavaScript... and any ECMA 
Script language works.

If others have read this thread, or this phat book:
http://www.debreuil.com/docs/ch01_Intro.htm

...or read Ralf's blog:
http://www.helpqlodhelp.com/blog/archives/64.html

...or used JavaScript OOP extensively, then they should already know.

AS3's different.  It exists on the traits, not the prototype.  Prototype is 
now read-only, and ... well, not really used anymore.  This is good and bad.

The Array example, however, I know for a fact is different.  It treats it 
like it should; if any instance adds something to the array, it immediately 
get it's own copy... although, I don't think prototype varialbes are even 
accessible.  I'll have to defer that one to someone more knowledgeable about 
AS3's inner workings.

Don't initialize arrays in your class, and initialize in your constructor or 
init functions, and you'll never have problems.



- Original Message - 
From: "Judah Frangipane" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" 
Sent: Thursday, December 29, 2005 5:56 PM
Subject: Re: [Flashcoders] Flash Class Array bug - Please verify


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" 
>>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.prototy

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" 
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" 
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 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" 
> 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" 
> 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 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" 
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" 
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 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 JesterXL
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" 
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" 
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


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 JesterXL
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" 
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


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

2005-12-29 Thread Glenn J. Miller
Yeah... that's a good point too... LOL

Peace...

--
Dok
Skyymap, Inc.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Nathan
Derksen
Sent: Thursday, December 29, 2005 3:33 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Flash Class Array bug - Please verify

I think you are missing the () in the constructor statement:


___
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 Glenn J. Miller
Flag on the play... ^_^

class myClass {
// initialize the array in the declarations
private var myArray:Array;

function myClass {
 this.myArray = new Array();
   trace("myArray.length="+myArray.length)
}

public function addToArray() {
   this.myArray.push(10);
   this.myArray.push(20);
}
}

Peace...
 
--
Dok
Skyymap, Inc.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Glenn J.
Miller
Sent: Thursday, December 29, 2005 3:33 PM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] Flash Class Array bug - Please verify

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

I think you are missing the () in the constructor statement:

function myClass {
  trace("myArray.length="+myArray.length)
}

Should be:

function myClass() {
  trace("myArray.length="+myArray.length)
}

Nathan
http://www.nathanderksen.com


On Dec 29, 2005, at 12:30 PM, Judah Frangipane wrote:

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


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

2005-12-29 Thread Glenn J. Miller
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