
Copy link to clipboard
Copied
Goal to make a mouse click counter. (a simple clicker/tally button that keeps track of the number of clicks a user makes).
- Progress -
- Button completed
- variable passed to text field completed.
- script passing correct variable to text field incomplete.
- Button completed
- Problem -
1. Counter Variable stays at 1 and does not increase by 1 when the button is clicked.
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
1 Correct answer
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);
}
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
?
Copy link to clipboard
Copied
?? We posted pretty much simultaneously if you're wondering why I'm almost mirroring your response. I did check before submitting and you weren't there beforee, but were there after. It's not the first time that's happened either way between us. I could say that great minds think alike, but that'd be too much of a stretch for me.
Copy link to clipboard
Copied
i know about the near-simultaneous posting stuff (as you know).
but your response was to me, not the op. that's what i was questioning but it must some kind of forum artifact.
Copy link to clipboard
Copied
Hah... I didn't even notice that... Maybe I have to count to three or something just for measure... or maybe my eyes were playing tricks on me when I checked. I've been on breaks between reseedings of a lawn all day, so maybe it's time for a nap instead of foruming.... just one more row to go though.
Copy link to clipboard
Copied
(that doesn't sound like a lot of fun. and weren't you supposed to reseed one month ago?)
Copy link to clipboard
Copied
( I have been seeding, weeding, and reseeding all summer... an extended heat spell arrived just in time to destroy my first attempt... then weeds grew in nice and thick during the heat spell where I hadn't seeded at all ... it's a longer story, but I'll stop here... )

Copy link to clipboard
Copied
It works.....
Thank you for all your help.

