初学AS3的几点技巧汇总
2020-07-17 13:18:50
供稿:网友
1.null和undefined的差 在於
null是指 有值
undefined是宣告未完全、 有宣告 性或 有指定 料型 (未 予值 做 料 型也算)
null==undefined但null!==undefined
所以我 常常要 查外部 有 有被 予值要用
if(外部 ==null){
外部 有被 予值
}
2.把 宣告在所有程式(FUNCTION)的最上面
3. 行container.addChild(ball_A); ,若container已存在ball_A 物件,在 行1次的功能在於,PLAYER 把原有的ball_A 掉,再重新加入ball_A,所以ball_A 示的 序就 成在最上面,若你要指定 示 序就用container.addChildAt(ball_A, 1); 指令(0-N),0 最底 N 目前最上面ㄧ
4.自 管理 示 序
trace(container.getChildAt(0).name); // ball_A
trace(container.getChildAt(1).name); // ball_C
trace(container.getChildAt(2).name); // ball_B
container.removeChild(ball_C);
trace(container.getChildAt(0).name); // ball_A
trace(container.getChildAt(1).name); // ball_B
5.delete 才 完整的把物件 掉removeChild只是移除 示清 而已,ㄧ 物件只能 一 container
6.其他好用的函式
contains(): Determines whether a display object is a child of a DisplayObjectContainer.
getChildByName(): Retrieves a display object by name.
getChildIndex(): Returns the index position of a display object.
setChildIndex(): Changes the position of a child display object.
swapChildren(): Swaps the front-to-back order of two display objects.
swapChildrenAt(): Swaps the front-to-back order of two display objects, specified by their index values.
7.取代AS 2.0 用[] 命名的方法
import flash.display.Sprite;
var container1:Sprite = new Sprite();
container1.name="allen";
container1.x=20;
var container2:Sprite = new Sprite();
container2.addChild(container1);
addChild(container2);
trace(container2.getChildByName("allen").x);