Actionscript 3 点击鼠标,调用函数?

Actionscript 3 点击鼠标,调用函数?,actionscript-3,flash,Actionscript 3,Flash,我很难弄清楚如何让我的动画工作,因此当单击一个对象(电影剪辑)时,会调用一个函数,并说该函数会从屏幕上删除该对象并显示爆炸。代码如下(来自my EnemyShip.as文件): 谢谢。我猜你的十字线会捕捉到所有点击事件,因为它总是在鼠标下。设置 crosshair_mc.mouseEnabled = crosshair_mc.mouseChildren = false; 使鼠标事件“透明”。有什么问题?你能测试一下你是否进入了mouseShoot事件监听器吗?基本上什么都没有发生。我正在单

我很难弄清楚如何让我的动画工作,因此当单击一个对象(电影剪辑)时,会调用一个函数,并说该函数会从屏幕上删除该对象并显示爆炸。代码如下(来自my EnemyShip.as文件):


谢谢。

我猜你的十字线会捕捉到所有点击事件,因为它总是在鼠标下。设置

  crosshair_mc.mouseEnabled = crosshair_mc.mouseChildren = false;

使鼠标事件“透明”。

有什么问题?你能测试一下你是否进入了mouseShoot事件监听器吗?基本上什么都没有发生。我正在单击对象,但它什么也没做。运行2个
trace()
测试:一个在
mouseShoot()
中,另一个在
kill()
中。看看他们是否开火。我不熟悉跟踪测试。我该怎么做?添加跟踪(“toto”);在你的任何地方,鼠标掌功能。然后查看控制台,看看是否发生了什么事情。在我的主postWell中添加了更多信息,我尝试将其放入main.as文件中,但出现了一个错误,错误是
通过静态类型类的引用访问可能未定义的属性MouseChildren
。同样的
mouseEnabled
你应该在设置crosshair\u mc和mouseChildren没有大写的M后写这个。我修复了它,但是现在爆炸动画继续循环,当我希望它在每次对象命中时显示一次disappear@David看来您是stackoverflow(SO)新手,欢迎。如果这个答案解决了您最初的问题,即无法让鼠标点击正常工作,那么您应该接受这个答案,并打开一个单独的问题,询问动画为什么循环(或搜索类似问题)。
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;
     }
   }
}
  crosshair_mc.mouseEnabled = crosshair_mc.mouseChildren = false;