·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

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

时间:2015-10-19 11:22酷播
[AS3]AS3点击空白区域隐藏鼠标动作

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

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

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器