Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why is it so hard to click my movieclip?

New Here ,
Nov 25, 2013 Nov 25, 2013

I have a movie clip (tempEnemyA) in an array (enemiesA). These enemies fall down and the player kills them by clicking on them. The higher the score = the faster the enemies drop. For some reason though, when there are a lot of enemies on stage, they start to become very hard to click. This is the code inside the 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);
}


this.dead3 activates this condition inside the stage layer:

if (tempEnemyA.dead3)
   
{
        scoreA
++;
        scoreA
++;
       
AntLevel.scoreA_txt.text = String(scoreA);
        enemiesA
.splice(g,1);
   
}

As a whole this is the whole code that spawns the enemies:


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);
           
}
       
}
   
}
}

TOPICS
ActionScript
413
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2013 Nov 25, 2013

You should try using the trace() function so that you can see of your clicking is not being processed or if it might be something else going on. 

For the first group of code you have which is inside the enemy, I don't see why you add the event listener back in after you remove the object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 27, 2013 Nov 27, 2013
LATEST

you are using setTimeOut,so after 2 seconds only you are calling the clikevent. I think because of that, you are having problem in clicking.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines