宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应
您当前的位置: > 博客2 > AS2与AS3技术

[AS3]as3中在可视化对象列表中移动对象位置的代码示例

2016-10-13 00:16:48 点击量:13 标签: 收藏本文

使用DisplayObectContainer类的setChildIndex()方法改变项目的位置,getChildIndex()和getChildAt()方法得到项目在显示列表中的位置。getChildIndex()返回当前对象的索引,getChildAt()返回当前对象的引用

 

  1. package {  
  2. import flash.display.Shape;  
  3. import flash.display.Sprite;  
  4. import flash.events.MouseEvent;  
  5. public class Sample1120 extends Sprite  
  6. {  
  7. public function Sample1120()  
  8. {  
  9. var arrColor:Array = [0xFF0000,0x00FF00,0x0000FF,0xFFFF00,0x00FFFF];  
  10. stage.addEventListener(MouseEvent.CLICK,OnClick);  
  11. for(var i:int=0; i<arrColor.length;i++)  
  12. {  
  13. var shape:Shape = AddElement(arrColor[i]);  
  14. shape.x = i*3+20;  
  15. shape.y = 20;  
  16. }  
  17. }  
  18. private function AddElement(color:int):Shape  
  19. {  
  20. var shape:Shape = new Shape();  
  21. shape.graphics.beginFill(color);  
  22. shape.graphics.drawCircle(10,10,30);  
  23. shape.graphics.endFill();  
  24. this.addChild(shape);  
  25. return shape;  
  26. }  
  27. private function OnClick(event:MouseEvent):void  
  28. {  
  29. this.setChildIndex(this.getChildAt(0),this.numChildren-1);  
  30. }  
  31. }  

 

ABOUT US
宜昌农人网络科技有限公司

我们是一家提供综合软件外包与弱电工程服务的技术公司。

业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。

公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室