ActionScript3系列课程(一)----基本元素
简述:Flash ActionScript3开发环境:Adobe Flex Builder 3(同时需要安装flashplayer_9_ax_debug.exe,要不无法显示结果,F11运行看结果).
代码如下:
代码如下:
package {
import flash.display.Sprite; //导入包
public class ExampleApplication extends Sprite
{
//构造函数
public function ExampleApplication()
{
trace("ActionScript3.0 基础知识");
ShowDefaultValue();
ShowDataType();
ShowOperator();
}
//显示默认值
function ShowDefaultValue():void
{
var a:int, b:uint,c:Number;
trace(a); // output: 0
trace(b); // output: 0
trace(c); // output: NaN(Not a Number)
var d:String;
trace(d); // output: null
var e:Boolean;
trace(e); // output: false
var f:Array;
trace(f); // output: null
var g:Object;
trace(g); // output: null
var h:Date;
trace(h); // output: null
var k;
trace(k); // output: undefined
var j:*;
trace(j); // output: undefined
}
//数据类型(AS3.0Z中所有数据都是对象)
function ShowDataType():void
{
//数字
var i:int= - 100; //int 是有符号(正/负)的整数型
trace(i); //output:-100
var u:uint = 100; // uint 是无符号的整数型
trace(u); //output: 100
var n:Number = 100.00; //Number 类型是64位的浮点型
trace(n); //output: 100
//字符串
var s:String = "This is My World!";
var ss:String = new String("This is My World"); //效果同上
trace(s); //output: This is My World!
trace(ss); //output: This is My World
trace("This is My World!长度为:"+s.length); //output: This is My World!长度为:17
//长量
const foo:String = "morningwang";
trace(foo); //output: morningwang
// foo="abcd"; 报错: 1049
//布尔值
const b:Boolean = true;
trace(b); //output: true
//数组:Array [一维]
var arr1:Array = [1,2,3,4]; //直接使用[] 操作符,建立一个含有整数1,2,3,4的数组
var arr2:Array = new Array(1,2,3,4); //使用Array类来进行和arr1同样的操作
var arr3:Array = new Array(4); //声明一个长度为4的空数组
trace(arr1); //output: 1,2,3,4
trace(arr2); //output: 1,2,3,4
trace(arr3); //output: ,,,
trace("arr3的长度为:"+arr3.length); //output: arr3的长度为:4
//数组:Array [二维或多维]
var ar1:Array = [[1,2,3],[4,5,6],[7,8,9]];
var ar2:Array = new Array(new Array(1,2,3), new Array(4,5,6),new Array(7,8,9)); //同上
var ar3:Array = new Array(3); //同上
ar3[0] = [1,2,3];
ar3[1] = [4,5,6];
ar3[2] = [7,8,9];
trace(ar1[1]); //output: 4,5,6
trace(ar1[1][1]); // output 5
//日期类型
var d:Date = new Date();
trace(d.toDateString()); // output: Thu Jun 12 2008
//Object
var ff:Object = {nikeName:"金鱼",web:"www.cnblogs.com/morningwang"};
ff["age"] = 24; //为对象动态添加属性
trace(ff.web); //output: www.cnblogs.com/morningwang
trace(ff.age); //output: 24
delete ff.age; //为对象动态删除属性
trace(ff.age); //output: undefined
}
//操作符
function ShowOperator():void
{
/* 以下操作符同C#
+ - * / %
+= -= *= /= %=
== != (等于运算符)
=== !=== (操作符两边不做类型转换,全等运算符)
>= <= > <
&& || !
? : (三元 相当于if-else)
*/
/*typeof is as */
//typeof以字符串的形式返回对象的类型
trace(typeof 10); //output : Number
//is 用来判断一个对象是否属于一种类型,返回布尔值
trace(9 is Number); // output: true
trace(9 is String); // output: false
//如果一个对象输入输入一种类型,那么就返回这个对象
trace(9 as Number); // output: 9
trace(9 as String); // output: null
// 判断一个对象是否属于某一集合
var ary:Array = [1,2,3];
trace(1 in ary); // output: true
}
}
}
import flash.display.Sprite; //导入包
public class ExampleApplication extends Sprite
{
//构造函数
public function ExampleApplication()
{
trace("ActionScript3.0 基础知识");
ShowDefaultValue();
ShowDataType();
ShowOperator();
}
//显示默认值
function ShowDefaultValue():void
{
var a:int, b:uint,c:Number;
trace(a); // output: 0
trace(b); // output: 0
trace(c); // output: NaN(Not a Number)
var d:String;
trace(d); // output: null
var e:Boolean;
trace(e); // output: false
var f:Array;
trace(f); // output: null
var g:Object;
trace(g); // output: null
var h:Date;
trace(h); // output: null
var k;
trace(k); // output: undefined
var j:*;
trace(j); // output: undefined
}
//数据类型(AS3.0Z中所有数据都是对象)
function ShowDataType():void
{
//数字
var i:int= - 100; //int 是有符号(正/负)的整数型
trace(i); //output:-100
var u:uint = 100; // uint 是无符号的整数型
trace(u); //output: 100
var n:Number = 100.00; //Number 类型是64位的浮点型
trace(n); //output: 100
//字符串
var s:String = "This is My World!";
var ss:String = new String("This is My World"); //效果同上
trace(s); //output: This is My World!
trace(ss); //output: This is My World
trace("This is My World!长度为:"+s.length); //output: This is My World!长度为:17
//长量
const foo:String = "morningwang";
trace(foo); //output: morningwang
// foo="abcd"; 报错: 1049
//布尔值
const b:Boolean = true;
trace(b); //output: true
//数组:Array [一维]
var arr1:Array = [1,2,3,4]; //直接使用[] 操作符,建立一个含有整数1,2,3,4的数组
var arr2:Array = new Array(1,2,3,4); //使用Array类来进行和arr1同样的操作
var arr3:Array = new Array(4); //声明一个长度为4的空数组
trace(arr1); //output: 1,2,3,4
trace(arr2); //output: 1,2,3,4
trace(arr3); //output: ,,,
trace("arr3的长度为:"+arr3.length); //output: arr3的长度为:4
//数组:Array [二维或多维]
var ar1:Array = [[1,2,3],[4,5,6],[7,8,9]];
var ar2:Array = new Array(new Array(1,2,3), new Array(4,5,6),new Array(7,8,9)); //同上
var ar3:Array = new Array(3); //同上
ar3[0] = [1,2,3];
ar3[1] = [4,5,6];
ar3[2] = [7,8,9];
trace(ar1[1]); //output: 4,5,6
trace(ar1[1][1]); // output 5
//日期类型
var d:Date = new Date();
trace(d.toDateString()); // output: Thu Jun 12 2008
//Object
var ff:Object = {nikeName:"金鱼",web:"www.cnblogs.com/morningwang"};
ff["age"] = 24; //为对象动态添加属性
trace(ff.web); //output: www.cnblogs.com/morningwang
trace(ff.age); //output: 24
delete ff.age; //为对象动态删除属性
trace(ff.age); //output: undefined
}
//操作符
function ShowOperator():void
{
/* 以下操作符同C#
+ - * / %
+= -= *= /= %=
== != (等于运算符)
=== !=== (操作符两边不做类型转换,全等运算符)
>= <= > <
&& || !
? : (三元 相当于if-else)
*/
/*typeof is as */
//typeof以字符串的形式返回对象的类型
trace(typeof 10); //output : Number
//is 用来判断一个对象是否属于一种类型,返回布尔值
trace(9 is Number); // output: true
trace(9 is String); // output: false
//如果一个对象输入输入一种类型,那么就返回这个对象
trace(9 as Number); // output: 9
trace(9 as String); // output: null
// 判断一个对象是否属于某一集合
var ary:Array = [1,2,3];
trace(1 in ary); // output: true
}
}
}