Could you please take a look to my code below, I need to increase the var misses by 1 every time the ball does not hit the goal area (it’s a penalty shootout game) but the matter is that it increases many times, this is the output message after making a trace for the variable value so you can have an idea:
It’s a fail 1
1
It’s a fail 2
2
It’s a fail 3
3
It’s a fail 4
4
It’s a fail 5
5
It’s a fail 6
6
It’s a fail 7
7
It’s a fail 8
8
It’s a fail 9
9
It’s a fail 10
10
And so on, my code is this and I’m pretty sure that the line affecting the result needed is the line stage.addEventListener(Event.ENTER_FRAME, onEnter); could you please give me some advice on how to work around this? Probably trying an alternative way to move the ball when is is moved in moveBall function? I have received a lot of help from you guys and I’m sorry for being so annoying, simply I’m still a newbie and get stuck at some points between my code and the ideas I have gathered so far. Here is my code
import flash.events.Event;
import flash.ui.Mouse;
import flash.geom.Point;
import flash.events.MouseEvent;
var misses:int= 0;//Here the var used trying to put the game over when player misses 3 shoots
var cursor:MovieClip; // mouse will be converted to a cursor (aim) which is the spot ball must follow
var nowX:Number; ;// will be used to move the ball
var nowY:Number;// will be used to move the ball
var isUpdating:Boolean = false; // will be used to control mouse events and other later on
var isClipSync:Boolean = false; // will be used to control mouse events and other later on
const START_BALL_POINT:Point = new Point(296,353); // returning the ball to original positions
function initializeGame():void
{
cursor = new Cursor();
addChild(cursor);
cursor.enabled = false;
//Mouse.hide();
stage.addEventListener(MouseEvent.CLICK, dragCursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onCursorMove);
}
function onCursorMove(e:MouseEvent):void
{
cursor.x = mouseX;
cursor.y = mouseY;
}
function onEnter(e:Event):void
{
isUpdating= true;
if(pateador_mc.currentFrame == 19)
{
pateador_mc.gotoAndStop(1);
}
//trace(pateador_mc.currentFrame);
//
if(pateador_mc.currentFrame > 11)
isClipSync = true;
moveBall();
}
function dragCursor(event:MouseEvent):void
{
if(isUpdating) return;
trace(isUpdating);
nowX = mouseX;
nowY = mouseY;
pateador_mc.play();
stage.addEventListener(Event.ENTER_FRAME, onEnter);// probably this is causing multiple count of trace events when I try to gather the failed shoots
}
initializeGame();
var mouse=this.Mouse;
var speed:int = 800;
var ease:int = 4;
var gravity:Number = 0.5;
function moveBall()
{
if(!isClipSync) return;
bola.x += 0.2 * (nowX - bola.x);
bola.y += 0.2 * (nowY - bola.y);
if(Math.abs(nowX-bola.x)<1 && Math.abs(nowY-bola.y)<1)
{
stage.removeEventListener(Event.ENTER_FRAME, onEnter);
isUpdating = false;
isClipSync = false;
var timer3:Timer = new Timer(3000,1);
timer3.addEventListener(TimerEvent.TIMER, accionRepetida3);
timer3.start();
function accionRepetida3(e:TimerEvent)
{
bola.x = START_BALL_POINT.x;
bola.y = START_BALL_POINT.y;}
}
if (bola.hitTestObject(goalie))
{
gol_mc.play(); /// All good at this point
red_mc.play();
}
//
else
{
misses++;
trace("It's a fail", misses);
}
}
I will really appreciate if some good pal takes the time to check on this, I promise when I get a better programmer I will help all those who need it.
Thanks again!
can you modify your code and give the output again?