2007年4月5日星期四

Package Block

Packages in ActionScript 3 are defined a little differently than they are in ActionScript 2. In ActionScript 3, the package path is no longer part of the class definition. Instead, it is part of a new block which contains your class, the package block defined with the package keyword. That gives you the following basic structure for AS3 files:

ActionScript Code:

package my.package.path {
class MyClass {
}
}


In AS2, it would look like the following:

ActionScript Code:

// ActionScript 2:
class my.
package.path.MyClass {
}


In fact, in AS3, all class files require a package block, even if they are not in a package.

ActionScript Code:

package {
class NotInAPackageClass {
}
}


Each package block can define a class or a function that is associated with the file. The class or function within the block should be defined with the same name as the file (minus the .as extension).

ActionScript Code:

package com.kirupa.utils {
function StripString(str:
String):void {
// ...
}
}


The above would be saved as StripString.as in a com/kirupa/utils folder.

0 评论: