TungWhat
TungWhat

Reputation: 13

How to make Click Counter restart from 0 using Flash Actionscript 3.0

We have assignment at school that we make an action: Everytime I click on the green button, the counter counts and the blue rectangle goes to the right, and when it hits the border of frame it returns from left and so does restart the counter from 0.

I was able to make it count and the blue rectangle returns, but what I need help with is how to make the counter restart to count from 0 when the rectangle returns? What code do I have to add or change?

Thank you very much before hand.

Belows is my script (a mess I know)

import fl.motion.MotionEvent;

var mynumber:int = 5

var numclick:int = 0;
mytext.text = ""

mynumber = mynumber+5;

trace(mynumber);

var myword:String = "Hello World!";

trace(5+5);
trace("5"+"5")

r1.x=0;
r1.y=0;

btn1.addEventListener(MouseEvent.CLICK,moveme);

function moveme(evt:MouseEvent):void {

    numclick++;

    if(r1.x < 550){

    r1.x = r1.x+100;


    mytext.text ="number of clicks: "+String(numclick);

    }else{
    r1.x = 0;

    mytext.text ="number of clicks: "+String(numclick);
}


}

Upvotes: 1

Views: 659

Answers (1)

DigitalD
DigitalD

Reputation: 586

just assign zero value to numclick variable within else statement

else{
    r1.x = 0;
    numclick=0;
    mytext.text ="number of clicks: "+String(numclick);
}

Upvotes: 1

Related Questions