PDA

View Full Version : If statement



Gooo
April 13th, 2009, 09:38 AM
Hi

I am using dynamic text to increment my value "dtext".

There are 3 buttons on the stage. When you click on one, it disappear and the counter becomes 1, ect.

The counter works, but there is something wrong with my if statement, because it never goes to frame 131.

My code:

var counter = 0;
dtext.text = counter;

if(counter < 3)
{
ball1_btn.addEventListener(MouseEvent.CLICK, gotoball1);
function gotoball1(event:MouseEvent):void
{
ball1_btn.alpha = 0;
dtext.text = ++counter;
}

ball2_btn.addEventListener(MouseEvent.CLICK, gotoball2);
function gotoball2(event:MouseEvent):void
{
ball2_btn.alpha = 0;
dtext.text = ++counter;
}

ball3_btn.addEventListener(MouseEvent.CLICK, gotoball3);
function gotoball3(event:MouseEvent):void
{
ball3_btn.alpha = 0;
dtext.text = ++counter;
}
}

else
gotoAndStop(131);


Can someone please help me?

Thanks

Daganev
April 13th, 2009, 04:14 PM
Try this:

var counter:Number = 0;
dtext.text = counter + "";

if(counter < 3)
{
if(!ball1_btn.hasEventListener(MouseEvent.CLICK, gotoball))
{
ball1_btn.addEventListener(MouseEvent.CLICK, gotoball);
ball2_btn.addEventListener(MouseEvent.CLICK, gotoball);
ball3_btn.addEventListener(MouseEvent.CLICK, gotoball);
}

}
else
{
gotoAndStop(131);
}

function gotoball(event:MouseEvent):void
{
event.currentTarget.alpha = 0;
dtext.text = ++counter + "";
}