当前位置: 主页 > 平面设计 > 初学AS3的几点技巧汇总

初学AS3的几点技巧汇总

  • 2022-02-04
  • 来源/作者: PS.ONEGREEN.ORG    / 佚名    
  • 4 次浏览

  1.null和undefined的差e在於

  null是指]有值

  undefined是宣告未完全、]有宣告@傩曰]有指定Y料型B(未x予值]做^Y料D型也算)

  null==undefined但null!==undefined

  所以我常常要z查外部涤]有被x予值要用

  if(外部==null){

  外部]有被x予值

  }

  2.把敌告在所有程式(FUNCTION)的最上面

  3.绦container.addChild(ball_A);r,若container已存在ball_A@物件,在绦1次的功能在於,PLAYER把原有的ball_Ah掉,再重新加入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 用[]B命名的方法

  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);

  ]e就是@一行container1.name="allen";直接指定name