2007年3月29日星期四

Unique Class Variables

In ActionScript 2, variables defined within a class's body were defined in the class's prototype object. This was an efficient means to handle variable definitions but it also meant that complex data types (such as Arrays) had a tendency to be "shared" among instances if not explicitly defined for instances within the class constructor. This is no longer a problem with ActionScript 3. Class variables defined in the class body are now unique to each class instance so this problem no longer occurs.

ActionScript Code:

class myClass{

private var list:Array = [1,2,3]; // bad for AS2, ok for AS3

public function myClass(){
// list should be defined here for AS2
}
}

0 评论: