2009年2月18日星期三

actionscript 2.0 基础知识回顾(数据类型)

1.Boolean
var my_lv:LoadVars = new LoadVars();
//success 是一个布尔值
my_lv.onLoad = function(success:Boolean) {
//如果 success 为 true,则输出 monthNames
if (success) {
trace(my_lv.monthNames);
//如果 success 为 false,则输出消息
} else {
trace("unable to load text file");
}
};
my_lv.load("http://www.helpexamples.com/flash/params.txt");
2.MovieClip
一个正方形
this.createEmptyMovieClip("square_mc", 1);
square_mc.lineStyle(1, 0x000000, 100);
square_mc.beginFill(0xFF0000, 100);
square_mc.moveTo(100, 100);
square_mc.lineTo(200, 100);
square_mc.lineTo(200, 200);
square_mc.lineTo(100, 200);
square_mc.lineTo(100, 100);
square_mc.endFill();
square_mc.onPress = function() {
this.startDrag();
};
square_mc.onRelease = function() {
this.stopDrag();
};

3.null
if (Selection.getFocus() == null) {
trace("no selection");
}

4.Number
var bottles:Number = 0;
bottles = 10 + Math.floor(Math.random() * 7);
trace("There are " + bottles + " bottles");

5.Object
var user:Object = new Object();
user.name = "Irving";
user.age = 32;
user.phone = "555-1234";

6.String
var greeting_str:String = "Welcome, " + firstName;


要在字符串中包含引号,请在它前面放置一个反斜杠字符 (\)。这就是所谓的将字符转义。在 ActionScript 中,还有一些只能用特殊的转义序列才能表示的字符。下表列出了所有 ActionScript 转义符:

转义序列
字符

\b 退格符 (ASCII 8)

\f 换页符 (ASCII 12)

\n 换行符 (ASCII 10)

\r 回车符 (ASCII 13)

\t 制表符 (ASCII 9)

\" 双引号

\' 单引号

\\ 反斜杠

\000 - \377 以八进制指定的字节

\x00 - \xFF 以十六进制指定的字节

\u0000 - \uFFFF 以十六进制指定的 16 位 Unicode 字符

7.undefined
if (init == undefined) {
trace("initializing app");
init = true;
}

8.Void
// 创建返回类型为 Void 的函数
function displayFromURL(url:String):Void {}

没有评论: