当前位置: 首页 > 图文教程 > Flash动画 > ActionScript > 初学AS3的几点技巧汇总

ActionScript
AS教程:ActionScript优化
AS3教程:密码强度验证
AS3编程心得
AS 3.0未公开的addFrameScript()方法
网页FLASH动画禁止右键菜单的方法
代码最优化实例
AS3实现以二进制方式播放mp3文件
Flex开发的基于浏览器的WEB操作系统
WEBJX收集的AS3非常有用的类库
通过实例学习flash AS3.0:案例二
Flash教程:ActionScript编程基础
Flash as入门(2):面向对象编程基础
Flex的背景和技术特点
参考:AS3及Flex的常用实用问题
Flash AS实例:随机移动动画特效
Flash AS教程:对拖到指定区域小球计数
Flash AS:用Point简单制作虚线特效
Flash的AS3代码制作模糊滤镜动画特效
Flash as入门(6):文本与字符串游戏实例
Flash as入门(7):创建影片剪辑

ActionScript 中的 初学AS3的几点技巧汇总


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-16   浏览: 79 ::
收藏到网摘: n/a

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);
沒錯就是這一行container1.name="allen";直接指定name