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

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

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

[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.          

 

热门文章推荐

请稍候...

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

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