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

[AS3]AS3点击空白区域隐藏鼠标动作

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

[AS3]AS3点击空白区域隐藏鼠标动作

  1. package  
  2.         import flash.display.Sprite; 
  3.         import flash.events.Event; 
  4.         import flash.events.MouseEvent; 
  5.          
  6.         /** 
  7.          * ... 
  8.          * @author BBB 
  9.          */ 
  10.         public class Main extends Sprite  
  11.         { 
  12.                 private var _bg:Sprite; 
  13.                 private var _btn:Sprite; 
  14.                 private var _popWindow:Sprite; 
  15.                  
  16.                 public function Main():void  
  17.                 { 
  18.                         if (stage) init(); 
  19.                         else addEventListener(Event.ADDED_TO_STAGE, init); 
  20.                 } 
  21.                  
  22.                 private function init(e:Event = null):void  
  23.                 { 
  24.                         removeEventListener(Event.ADDED_TO_STAGE, init); 
  25.                         // entry point 
  26.                          
  27.                         _bg = new Sprite(); 
  28.                         _bg.graphics.beginFill(0xCCCCCC); 
  29.                         _bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); 
  30.                         addChild(_bg); 
  31.                          
  32.                         _btn = new Sprite(); 
  33.                         _btn.graphics.beginFill(0xFF0000); 
  34.                         _btn.graphics.drawCircle(0, 0, 20); 
  35.                         addChild(_btn); 
  36.                         _btn.x = 100
  37.                         _btn.y = 100
  38.                          
  39.                         _popWindow = new Sprite(); 
  40.                         _popWindow.graphics.beginFill(0x111111); 
  41.                         _popWindow.graphics.drawRoundRect(0, 0, 160, 120, 10, 10); 
  42.                         _popWindow.x = (stage.stageWidth-_popWindow.width) * .5; 
  43.                         _popWindow.y = (stage.stageHeight - _popWindow.height) * .5; 
  44.                         _popWindow.addEventListener(MouseEvent.CLICK, onClick2); 
  45.                          
  46.                         var child:Sprite = new Sprite(); 
  47.                         child.graphics.beginFill(0x00FF00); 
  48.                         child.graphics.drawCircle(0, 0, 10); 
  49.                         child.x = 50
  50.                         child.y = 50
  51.                         child.addEventListener(MouseEvent.CLICK, onClick3); 
  52.                         _popWindow.addChild(child); 
  53.                          
  54.                         stage.addEventListener(MouseEvent.CLICK, onClick); 
  55.                 } 
  56.                  
  57.                 private function onClick3(e:MouseEvent):void  
  58.                 { 
  59.                         trace("child"); 
  60.                 } 
  61.                  
  62.                 private function onClick2(e:MouseEvent):void  
  63.                 { 
  64.                         trace("popWindow"); 
  65.                         e.stopPropagation(); 
  66.                 } 
  67.                  
  68.                 private function onClick(e:MouseEvent):void  
  69.                 { 
  70.                         if (e.target == _btn) { 
  71.                                 addChild(_popWindow); 
  72.                         }else { 
  73.                                 if (contains(_popWindow)) { 
  74.                                         removeChild(_popWindow); 
  75.                                 } 
  76.                         } 
  77.                 } 
  78.                  
  79.         } 
  80.          

 

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

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

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

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