Skip to main content
October 3, 2010
Answered

Simple Mouse Click Counter help

  • October 3, 2010
  • 2 replies
  • 1954 views

Goal to make a mouse click counter. (a simple clicker/tally button that keeps track of the number of clicks a user makes).

  1. Progress -
    1. Button completed
    2. variable passed to text field completed.
    3. script passing correct variable to text field incomplete.
  2. Problem -

          1. Counter Variable stays at 1 and does not increase by 1 when the button is clicked.

Link to .fla

script

var myVar=0;

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField;

var fl_TextToDisplay:String = myVar;

function fl_ClickToPosition(event:MouseEvent):void

{

fl_TF = new TextField();

fl_TF.autoSize = TextFieldAutoSize.LEFT;

fl_TF.background = true;

fl_TF.border = true;

fl_TF.x = 100;

fl_TF.y = 100;

fl_TF.text = fl_TextToDisplay;

addChild(fl_TF);

myVar++;

}

any and all help greatly appreciated.

Thank You

This topic has been closed for replies.
Correct answer Ned Murphy

Try:

var myVar=0;

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField;
fl_TF = new TextField();
fl_TF.autoSize = TextFieldAutoSize.LEFT;
fl_TF.background = true;
fl_TF.border = true;
fl_TF.x = 100;
fl_TF.y = 100;
fl_TF.text = String(myVar);
addChild(fl_TF);

function fl_ClickToPosition(event:MouseEvent):void
{
     myVar++;
     fl_TF.text = String(myVar);
}

2 replies

October 3, 2010

It works.....

Thank you for all your help.

kglad
Community Expert
Community Expert
October 3, 2010

use:


var myVar:uint=0;

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField = new TextField();

fl_TF.autoSize = TextFieldAutoSize.LEFT;

fl_TF.background = true;

fl_TF.border = true;

fl_TF.x = 100;

fl_TF.y = 100;

fl_TF.text = myVar.toString();

addChild(fl_TF);

function fl_ClickToPosition(event:MouseEvent):void

{

myVar++;

fl_TF.text=myVar.toString();

}


Ned Murphy
Ned MurphyCorrect answer
Legend
October 3, 2010

Try:

var myVar=0;

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

var fl_TF:TextField;
fl_TF = new TextField();
fl_TF.autoSize = TextFieldAutoSize.LEFT;
fl_TF.background = true;
fl_TF.border = true;
fl_TF.x = 100;
fl_TF.y = 100;
fl_TF.text = String(myVar);
addChild(fl_TF);

function fl_ClickToPosition(event:MouseEvent):void
{
     myVar++;
     fl_TF.text = String(myVar);
}

kglad
Community Expert
Community Expert
October 3, 2010

?