Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-16-2012, 06:53 PM   #1
Registered User
Join Date: May 2012
Posts: 1
Default [AS3] Simple score counter

Hi, I'm completely new to Flash and AS3 and I've got a small issue...

On my stage I have a simple button and a dynamic text field for score.

Each time you click the button the counter should add 1 point to the score number

this is my code:


var score:uint;

scoreinstance.text = " " + score;

this.addpointbtn.addEventListener(MouseEvent.CLICK ,clickListener1);
function clickListener1(event:MouseEvent):void
score ++;


the buttons instance name is addpointbtn. I've clicked on the dynamic text field and chosen Embed and simply added a Font 1 to it.. No idea why I had to do this but I got an error message if I didn't.

Would someone please help me make this work?
in_bloom is offline   Reply With Quote
Old 05-17-2012, 12:45 AM   #2
tango88's Avatar
Join Date: Aug 2006
Posts: 289

Here's what you need:

var score:uint;

scoreinstance.text = "0";

this.addpointbtn.addEventListener(MouseEvent.CLICK ,clickListener1);
function clickListener1(event:MouseEvent):void
score ++;
scoreinstance.text = String(score);
You needed to update the score text AFTER the button is clicked, not before.

A tip for you: if you don't want to mess around with embedded fonts, just sent the font type to 'sans'
Games and more:
Flashbynight.com | Tutes | Twitter
tango88 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:21 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.