Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 为什么点击我的电影唇这么难?_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 为什么点击我的电影唇这么难?

Actionscript 3 为什么点击我的电影唇这么难?,actionscript-3,flash,Actionscript 3,Flash,我有一个数组(enemiesA)中的电影剪辑(tempEnemyA)。这些敌人倒下,玩家通过点击他们来杀死他们。分数越高=敌人下降得越快。然而,由于某种原因,当舞台上有很多敌人时,他们开始变得很难点击。这是tempEnemyA中的代码: import flash.events.MouseEvent; import flash.display.MovieClip; import fl.motion.Animator; import flash.events.*; import flash.util

我有一个数组(enemiesA)中的电影剪辑(tempEnemyA)。这些敌人倒下,玩家通过点击他们来杀死他们。分数越高=敌人下降得越快。然而,由于某种原因,当舞台上有很多敌人时,他们开始变得很难点击。这是tempEnemyA中的代码:

import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.motion.Animator;
import flash.events.*;
import flash.utils.setTimeout;

this.addEventListener(MouseEvent.CLICK, killM);
this.dead3 = false;

function killM(event:MouseEvent):void 
{
    this.dead3=true;
    this.mouseChildren=false
    gotoAndPlay(31);
    this.removeEventListener(MouseEvent.CLICK, killM);
  flash.utils.setTimeout(removeSelfM,2000);

}

function removeSelfM():void
{
    this.parent.removeChild(this);
    this.addEventListener(MouseEvent.CLICK, killM);
}
此.3激活阶段层内的该条件:

if (tempEnemyA.dead3) 
    {
        scoreA++;
        scoreA++;
        AntLevel.scoreA_txt.text = String(scoreA);
        enemiesA.splice(g,1);
    } 
总的来说,这是产生敌人的全部代码:

function makeEnemiesA():void
{
    var chance:Number = Math.floor(Math.random() * 150);
    if (chance <= + levelA)
    {


        //Make sure a Library item linkage is set to Enemy...
        tempEnemyA = new Mosquito();
        tempEnemyA.speed = 2
        //Math.random(); gets a random number from 0.0-1.0
        tempEnemyA.x = Math.round(Math.random() * 550);
        addChild(tempEnemyA);
        enemiesA.push(tempEnemyA);
        tempEnemyA.speed = enemyBaseSpeed3 + ((levelA - 1) * speedLevelInc3);
         if (tempEnemyA.speed > MAX_SPEED3)
         {
        tempEnemyA.speed = MAX_SPEED3;

        }
    }
}

function moveEnemiesA():void
{
    var tempEnemyA:MovieClip;

    for (var g:int =enemiesA.length-1; g>=0; g--)
    {

     tempEnemyA=enemiesA[g];
    if (tempEnemyA.dead3) 
    {
        scoreA++;
        scoreA++;
        AntLevel.scoreA_txt.text = String(scoreA);
        enemiesA.splice(g,1);
    } 
         else // Enemy is still alive and moving across the screen
        {
            //rotate the enemy between 10-5 degrees
            tempEnemyA.rotation += (Math.round(Math.random()*.4));
            //Find the rotation and move the x position that direction
            tempEnemyA.x -=  (Math.sin((Math.PI/180)*tempEnemyA.rotation))*tempEnemyA.speed;
            tempEnemyA.y +=  (Math.cos((Math.PI/180)*tempEnemyA.rotation))*tempEnemyA.speed;
            if (tempEnemyA.x < 12)
            {
                tempEnemyA.x = 12;
            }
            if (tempEnemyA.x > stage.stageWidth - offset2)
            {
                tempEnemyA.x = stage.stageWidth - offset2;
            }
            if (tempEnemyA.y > stage.stageHeight)
            {
                removeEnemyA(g);
                livesA--;
                AntLevel.livesA_txt.text = String(livesA);
            }
        }
    }
}
函数makeEnemiesA():void
{
var chance:Number=Math.floor(Math.random()*150);
如果(机会最大速度3)
{
tempEnemyA.speed=最大速度3;
}
}
}
函数moveEnemiesA():void
{
var tempEnemyA:MovieClip;
对于(变量g:int=enemiesA.length-1;g>=0;g--)
{
tempEnemyA=enemiesA[g];
如果(临时死亡3)
{
scoreA++;
scoreA++;
AntLevel.scoreA_txt.text=字符串(scoreA);
灌肠接头(g,1);
} 
否则//敌人还活着,正在屏幕上移动
{
//将敌人旋转10-5度
tempEnemyA.rotation+=(Math.round(Math.random()*.4));
//找到旋转并将x位置移动到该方向
tempEnemyA.x-=(Math.sin((Math.PI/180)*tempEnemyA.rotation))*tempEnemyA.speed;
tempEnemyA.y+=(Math.cos((Math.PI/180)*tempEnemyA.rotation))*tempEnemyA.speed;
if(tempEnemyA.x<12)
{
tempEnemyA.x=12;
}
如果(tempEnemyA.x>stage.stageWidth-offset2)
{
tempEnemyA.x=stage.stageWidth-偏移量2;
}
if(tempEnemyA.y>stage.stageHeight)
{
removeEnemyA(g);
利维萨--;
AntLevel.livesA_txt.text=字符串(livesA);
}
}
}
}

为什么要在
removeSelfM()
中向敌人添加事件侦听器?它不应该在那里。如果一个对象附加了监听器,但不再被引用,那么它会在内存中持续存在,从而导致“内存泄漏”。这可能是问题的根源。由于某些原因,问题仍然存在。可能在
if(tempEnemyA.y>stage.stageHeight)
部分通过
tempfoint.killM(null)
调用将敌人标记为死亡?我看到,如果一个敌人跨过舞台,它不会被正确地清除。也可以在
killM()
函数中添加
if(event)event.UpdateAfterEvent()
If(event)
,因为我们可以用null参数调用它。还添加一个带有跟踪坐标的单鼠标事件侦听器,并在该侦听器中跟踪
getObjectsUnderPoint()
,以调试问题。