2013-04-24 4 views
0

내 애니메이션을 작동시키는 방법을 알아내는 데 어려움이 있습니다. 그래서 객체 (무비 클립)를 클릭하면 함수가 호출되고 함수는 화면에서 객체를 제거하고 폭발을 표시합니다. (내 EnemyShip.as이 파일에서) 코드는 다음과 같습니다 :마우스 클릭시 함수를 호출 하시겠습니까?

package 
{ 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.utils.Timer; 
import flash.events.MouseEvent; 

public class EnemyShipMed extends MovieClip 
{ 
    var speed:Number; 

    function EnemyShipMed() 
    { 
     this.x = 800; 
     this.y = Math.random() * 275 + 75; 
     speed = Math.random()*5 + 6; 
     addEventListener("enterFrame", enterFrame); 
     addEventListener(MouseEvent.MOUSE_DOWN, mouseShoot); 
    } 

     function enterFrame(e:Event) 
     { 
      this.x -= speed; 
      if(this.x < -100) 
      { 
       removeEventListener("enterFrame", enterFrame); 
       stage.removeChild(this); 
      } 
     } 

     function kill() 
     { 
      var explosion = new Explosion(); 
      stage.addChild(explosion); 
      explosion.x = this.x; 
      explosion.y = this.y; 
      removeEventListener("enterFrame", enterFrame); 
      stage.removeChild(this); 
     } 

     function mouseShoot(event:MouseEvent) 
     { 
      kill(); 
     } 
    } 
} 

내가 십자와 마우스 포인터를 (동영상 클립이 crosshair_mc라고 함)를 교체했다. 여기에 내 Main.as 파일에있는 내용이 있습니다.

package { 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.utils.Timer; 
import flash.ui.Mouse; 
import flash.media.Sound; 
import flash.media.SoundChannel; 

public class Main extends MovieClip { 

public var crosshair:crosshair_mc; 
var enemyShipTimer:Timer; 
var enemyShipTimerMed:Timer; 
var enemyShipTimerSmall:Timer; 

public function Main() 
{ 
    enemyShipTimer = new Timer(2000); 
    enemyShipTimer.addEventListener("timer", sendEnemy); 
    enemyShipTimer.start(); 

    enemyShipTimerMed = new Timer(2500); 
    enemyShipTimerMed.addEventListener("timer", sendEnemyMed); 
    enemyShipTimerMed.start(); 

    enemyShipTimerSmall = new Timer(2750); 
    enemyShipTimerSmall.addEventListener("timer", sendEnemySmall); 
    enemyShipTimerSmall.start(); 

    //This creates a new instance of the cursor movie clip and adds it onto 
    //the stage using the addChild method. 
    crosshair = new crosshair_mc(); 
    addChild(crosshair); 

    //Hides the default cursor on the stage so it will not be shown. 
    Mouse.hide(); 

    //Adds an event listener onto the stage with the enter frame event which 
    //repeatedly executes the moveCursor function. 
    stage.addEventListener(Event.ENTER_FRAME, moveCursor); 
} 

function sendEnemy(e:Event) 
{ 
    var enemy = new EnemyShip(); 
    stage.addChild(enemy); 
    stage.addChild(crosshair);//brings crosshair to topmost level on stage 
} 

function sendEnemyMed(e:Event) 
{ 
    var enemymed = new EnemyShipMed(); 
    stage.addChild(enemymed); 
    stage.addChild(crosshair);//brings crosshair to topmost level on stage 
} 

function sendEnemySmall(e:Event) 
{ 
    var enemysmall = new EnemyShipSmall(); 
    stage.addChild(enemysmall); 
    stage.addChild(crosshair);//brings crosshair to topmost level on stage 
} 
//This function set the x & y positions of the custom cursor to the x & y positions 
//of the default cursor. 
function moveCursor(event:Event) 
{ 
    crosshair.x=mouseX; 
    crosshair.y=mouseY; 
    } 
    } 
} 

감사합니다.

+1

무엇이 문제입니까? mouseShoot eventListener를 입력하면 테스트 할 수 있습니까? – Kodiak

+0

기본적으로 아무 것도 일어나지 않습니다. 나는 물건을 클릭하고 아무것도하지 않고있다. – David

+0

2 개의'trace()'테스트를 실행합니다 : 하나는'mouseShoot()'에, 또 하나는'kill()'에 있습니다. 그들이 발사되는지 확인하십시오. – David

답변

1

내 생각에 십자형 커서는 항상 마우스 아래에 있기 때문에 모든 클릭 이벤트를 포착 할 것입니다.

crosshair_mc.mouseEnabled = crosshair_mc.mouseChildren = false; 

마우스 이벤트의 경우 "투명하게"설정하십시오.

+0

내 메인 포스트에 더 많은 정보를 추가했습니다. – David

+0

그래서 내 힌트를 시도했는데 작동하지 않았습니까? – Kodiak

+0

글쎄, 내가 Main.as 파일에 넣으려고했는데,'정적 유형 Class를 가진 참조를 통해 아마도 정의되지 않은 속성 MouseChildren에 접근했다 .'라는 오류가 발생했습니다. 'mouseEnabled'와 동일합니다. – David

관련 문제