当前位置: 移动技术网 > IT编程>UI设计>设计软件 > 初学AS3的几点技巧汇总

初学AS3的几点技巧汇总

2019年03月23日  | 移动技术网IT编程  | 我要评论
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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网