2014-10-23 2 views
0

내가 얻으려고하는 것은 카우보이가 클릭되었을 때 사라지는 것입니다. 카우보이가 클릭되었을 때 아무런 흔적도 남기지 않았다.ActionScript3 MouseEvent.CLICK이 오류없이 작동하지 않습니다.

프로그램을 실행할 때 오류가 발생하지 않습니다. 나는 이유를 알 수 없다. 다음은 내 코드입니다

package 
{ 
    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.display.Bitmap; 
    import flash.ui.Mouse; 
    import flash.events.MouseEvent; 

    /** 
    * ... 
    * @author Callum Singh 
    */ 
    public class Main extends Sprite 
    { 
     public var gun:crosshair; 
     public var cowboy:enemy; 

     public function Main():void 
     { 
      if (stage) init(); 
      else addEventListener(Event.ADDED_TO_STAGE, init); 
     } 

     private function init(e:Event = null):void 
     { 
      removeEventListener(Event.ADDED_TO_STAGE, init); 

      gun = new crosshair(); 
      stage.addChild (gun); 
      addEventListener(Event.ENTER_FRAME, moveCrosshair); 

      cowboy = new enemy(); 
      cowboy.x = Math.random() * 600; 
      cowboy.y = Math.random() * 400; 
      stage.addChild (cowboy); 
      addEventListener(MouseEvent.CLICK, handleShoot); 
     } 

     private function moveCrosshair(e:Event):void 
     { 
      gun.x = mouseX -120; 
      gun.y = mouseY -115; 

     } 

     private function handleShoot(e:MouseEvent):void 
     { 
      if (e.target == cowboy) 
       { 
        cowboy.visible = false; 
       } 
     } 

    } 

} 

답변

0

당신이 된 MouseEvent에 MouseEvent.CLICK을 변경 때때로 카우보이 객체에 리스너를 추가해야합니다. MOUSE_DOWN이 도움이됩니다.

cowboy.addEventListener(MouseEvent.MOUSE_DOWN, handleShoot); 
+0

치료를 받았다. 감사. –

관련 문제