初學(xué)AS3的幾點技巧匯總
互聯(lián)網(wǎng) 發(fā)布時間:2008-10-06 01:25:19 作者:佚名
我要評論
1.null和undefined的差別在於
null是指沒有值
undefined是宣告未完全、沒有宣告這個屬性或沒有指定資料型態(tài)(未賦予值沒做過資料轉(zhuǎn)型也算)
null==undefined但null!==undefined
所以我們常常要檢查外部變數(shù)有沒有被賦予值要用
if(外部變數(shù)==null){
外部變數(shù)沒有被賦予值
1.null和undefined的差別在於
null是指沒有值
undefined是宣告未完全、沒有宣告這個屬性或沒有指定資料型態(tài)(未賦予值沒做過資料轉(zhuǎn)型也算)
null==undefined但null!==undefined
所以我們常常要檢查外部變數(shù)有沒有被賦予值要用
if(外部變數(shù)==null){
外部變數(shù)沒有被賦予值
}
2.把變數(shù)宣告在所有程式(FUNCTION)的最上面
3.執(zhí)行container.addChild(ball_A);時,若container已存在ball_A這個物件,在執(zhí)行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只是移除顯示清單而已,ㄧ個物件只能對應(yīng)一個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 用[]動態(tài)命名的方法
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);
沒錯就是這一行container1.name="allen";直接指定name
null是指沒有值
undefined是宣告未完全、沒有宣告這個屬性或沒有指定資料型態(tài)(未賦予值沒做過資料轉(zhuǎn)型也算)
null==undefined但null!==undefined
所以我們常常要檢查外部變數(shù)有沒有被賦予值要用
if(外部變數(shù)==null){
外部變數(shù)沒有被賦予值
}
2.把變數(shù)宣告在所有程式(FUNCTION)的最上面
3.執(zhí)行container.addChild(ball_A);時,若container已存在ball_A這個物件,在執(zhí)行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只是移除顯示清單而已,ㄧ個物件只能對應(yīng)一個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 用[]動態(tài)命名的方法
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);
沒錯就是這一行container1.name="allen";直接指定name
相關(guān)文章

flash cs6鼠標(biāo)跟隨效果實現(xiàn)代碼分享
flash cs6想要實現(xiàn)鼠標(biāo)跟隨效果?該怎么制作呢?今天我們就來看看使用as2.0實現(xiàn)鼠標(biāo)跟隨效果的教程,需要的朋友可以參考下2019-05-19
Flash cs6怎么使用代碼輸入中英文文本?Flash cs6中可以使用文字工具直接輸入文本,也可以使用代碼來輸入文本,該怎么使用代碼輸入文本呢?請看下文詳細(xì)的教程,需要的朋友2018-03-11
flash as3.0抽象類怎么定義? as3.0中有很多抽象類,該怎么定義抽象類和抽象方法呢?下面我們就來看看簡單的例子,需要的朋友可以參考下http://www.fzitv.net/softs/408402.2018-02-28
flash cs6中怎么使用ActionScript3.0?
flash cs6中怎么使用ActionScript3.0?flash cs6中想要使用ActionScript3.0功能,該怎么使用呢?下面我們就來看看詳細(xì)的教程,需要的朋友可以參考下2018-01-25
Flash中怎么實現(xiàn)鼠標(biāo)點擊決定圖像位置?
本教程給大家分享一個Flash小教程,教大家在Flash CS6中怎么實現(xiàn)鼠標(biāo)點擊決定圖像位置?方法很簡單,感興趣的朋友歡迎前來一起分享學(xué)習(xí)2018-01-12
本教程教腳本之家的ActionScript教程學(xué)習(xí)者在Flash中如何用代碼將圖片放在自己想要的舞臺位置,教程講解的詳細(xì),感興趣的朋友歡迎前來分享學(xué)習(xí)2017-11-20
在Flash CS6中使用with函數(shù)繪制背景圖教程
本教程教腳本之家的ActionScript教程學(xué)習(xí)者如何在Flash CS6中使用with函數(shù)繪制背景圖?教程一步步講解的挺詳細(xì),方法也不難,非常適合Flash新手入門學(xué)習(xí)2017-11-18
Flash怎么設(shè)置元件坐標(biāo)?flash使用代碼設(shè)置元件的坐標(biāo)的教程
Flash怎么設(shè)置元件坐標(biāo)?flash中導(dǎo)如的元件需要添加坐標(biāo),該怎么定位元件坐標(biāo)呢?下面我們就來看看flash使用代碼設(shè)置元件的坐標(biāo)的教程,需要的朋友可以參考下2017-10-11
Flash怎么制作來回?fù)u擺的花朵的動畫?Flash中想要給花朵制作一段搖擺的動畫效果,該怎么制作呢?下面我們就來看看詳細(xì)的教程,很簡單,需要的朋友可以參考下2017-05-23
Flash怎么制作流動七彩色的文字?想要讓文字動起來,該怎么使用flash給文字制作一個流動七彩色的動畫呢?下面我們就來看看詳細(xì)的教程,需要的朋友可以參考下2017-04-23











