ForumsProgramming ForumAS3 Score Help

11 5408
alsage
offline
alsage
132 posts
Nomad

So I am having a bit trouble trying to get a score together. I have looked all over the internet and I have found somethings but I don't completely get it... so can any one give me the code for it please.

Thanks

  • 11 Replies
Darkroot
offline
Darkroot
2,763 posts
Peasant

What do you mean by score, like the game score or highscore?

alsage
offline
alsage
132 posts
Nomad

the game score... like lets say my hero hitTests a coin and I get a score of +10

Darkroot
offline
Darkroot
2,763 posts
Peasant

Well create a variable and when the hero hitTests a coin make it var += 10 (which is shorthand for var = var + 10). You might also want a dynamic text box on stage to display the score if you haven't.

alsage
offline
alsage
132 posts
Nomad

The main problem I am having is showing it on a screen using a dynamic text

Darkroot
offline
Darkroot
2,763 posts
Peasant

It's relatively simple but tricky. First create a textbox and set it as dynamic instead of static in the properties window.

http://img403.imageshack.us/i/capturebre.png/

Then add some basic magic code.

var number:Number = 5
var score:String = String(number)
numbertextfield.text = score


and Voilia! That's it, you can edit the visual look of the text in the properties window also.

Darkroot
offline
Darkroot
2,763 posts
Peasant

http://img403.imageshack.us/i/capturebre.png/

Grumbles, AG didn't post my last post previously and when I redid it I made a mistake in the image posting. I also wish AG had bb code for code comments..

alsage
offline
alsage
132 posts
Nomad

ooooh its string :P
lol thanks a lot man I really appreciate it =D

alsage
offline
alsage
132 posts
Nomad

sorry if I am a bit annoying but now its having problems where the score isnt refreshing itself... I used trace on "number" and it was showing that it was changing but I think the string only happens once and than stops right after keeping it from changing.

Darkroot
offline
Darkroot
2,763 posts
Peasant

At this point I'm not sure since I can't test my ideas and I haven't touched flash in a while so I'm not sure if a frame or time based update system would be better so here it goes.

stage.addEventListener(Event.ENTER_FRAME,onFrameLoop);

var number:Number = 5

function onFrameLoop(evt:Event):void {
var score:String = String(number)
blah.text = score

}

alsage
offline
alsage
132 posts
Nomad

yep that was it
and I haven't used flash in a while so I have forgotten a lot xD
thanks again man

Darkroot
offline
Darkroot
2,763 posts
Peasant

No problem it's good to have someone kick me into actually working :P.

Thought I am surprised the frame based system worked. But in retrospect I can see it doing better than a time based system.

Showing 1-11 of 11