初学者ps技巧:初学AS3的几点窍门技巧汇总

  1.null和und差別在於

  null是指沒有值

  und是宣告未完全、沒有宣告這個屬性或沒有指定資料型態(未賦予值沒做過資料轉型也算)

  nullund但null!und

  所以我們常常要檢查外部變數有沒有被賦予值要用

  (外部變數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.

  ChildIndex: 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, specied by their index values.

  7.取代AS 2.0 用動態命名思路方法

  import flash.display.Sprite;

  var container1:Sprite = Sprite;

  container1.name="allen";

  container1.x=20;

  var container2:Sprite = Sprite;

  container2.addChild(container1);

  addChild(container2);

  trace(container2.getChildByName("allen").x);

  沒錯就是這行container1.name="allen";直接指定name

Tags:  电脑小技巧

延伸阅读

最新评论

发表评论