从基础开始深入学Flash AS3教程(6)(译文)

14,SimpleButton实例
AS3现在有一个新的类:SimpleButton(flash.display.SimpleButton)。这个类允许你通过AS创建一个按钮。

var myButton:SimpleButton = new SimpleButton();
SimpleButton类有4个属性分别代表按钮的四个不同状态:upState,overState,downState和hitAreaState。你可以为每一个状态创建一个新的显示对象,然后将显示对象赋予SimpleButton的各种状态:

myButton.upState = mySprite1;
myButton.overState = mySprite2;
myButton.downState = mySprite3;
myButton.hitAreaState = mySprite4;
15,数组定义中的逗号
本文非直接翻译,原文解释部分如下:

When defining arrays in ActionScript 3 using the shorthand array access operator (brackets), you can now have a trailing comma following the last element without causing an error (like in PHP). This makes working with multi-line array definitions a little less error-prone when rearranging elements.
先来看一个例子:

var myList:Array = [
"The",
"quick",
"brown",
"fox",
];
在AS1和2中,"fox"后的逗号会导致一个编译错误,但是在AS3中不会了。
注意,这个逗号只是在使用[]定义数组的时候有效,使用Array()或new Array()的时候是无效的。
16,包块
AS3中的包定义方式和AS2中有所不同。在AS3中,包路径不再是类定义的一部分,而是使用一个包块来包含类。定义包块使用的是package标签,如下:

package my.package.path {
class MyClass {
}
}
而在AS2中,应该是下面的样式:

// ActionScript 2:
class my.package.path.MyClass {
}
实际上,在AS3中,所有的类都必须定义在包里面,如果一个类不属于任何一个包,也需要使用空的包路径来定义:
package {
class NotInAPackageClass {
}
}
每一个包块可以将一些有关联的类或者方法包含在一个文件里面。文件中包块里的类或方法必须使用和文件名相同的名称:

package com.kirupa.utils {
function StripString(str:String):void {
// ...
}
}
上面的代码应该保存在一个名称为StripString.as的文件中,并放在路径为com/kirupa/utils的文件夹里。