View Full Version : Updating Dynamic Text Box
SonOfChaos
June 16th, 2009, 02:45 PM
Okay everyone. Noob here trying to learn some stuff, so far I've half worked out this problem. Now, I've got this code that creates a dynamic textfield, converts 'score' to a string, displays string, and updates the value of score. Well, I've traced it and the value of score updates, but the value displayed in the text box stays the same. How do I get the value in the textbox to update/change.
//
var scoreString:String = String(score);
var scoreNumber:TextField = new TextField();
addChild(scoreNumber);
scoreNumber.type = TextFieldType.DYNAMIC;
scoreNumber.text = scoreString;//scoreString is 'score converted to a string
scoreNumber.x = scoreText.width + 5;//placement
scoreNumber.textColor = 0xFF0000FF;//color of text
*in the hit detection
score += 5; //score is a public var:Number = 0
tic
June 16th, 2009, 02:55 PM
try putting the score in an enterframe event
So that it keeps updating the score.
.ral:cr
June 16th, 2009, 03:02 PM
score += 5;
scoreNumber.text = String(score);
SonOfChaos
June 16th, 2009, 03:30 PM
I've tried the EventListener and I keep having scope problems. I'm so sick of this. The method you recommend ral does not update the field. Anyway have a tutorial written in AS3 (not that kinda AS3, but still AS2 garbage), I've searched google but the ones I've found have been lame. ARGH!!!
BoppreH
June 16th, 2009, 03:44 PM
I've tried the EventListener and I keep having scope problems. I'm so sick of this. The method you recommend ral does not update the field. Anyway have a tutorial written in AS3 (not that kinda AS3, but still AS2 garbage), I've searched google but the ones I've found have been lame. ARGH!!!
The problem is that you are just updating the score value, and it has no connection to the text field. You have to update the text field's text just like ral said. If you are having problems, post some more of the code so we analyze the source of the scope errors.
tic
June 16th, 2009, 04:17 PM
public var scoreString:String = String(score);
public var scoreNumber:TextField = new TextField();
public function init():void
{
addChild(scoreNumber);
scoreNumber.type = TextFieldType.DYNAMIC;
scoreNumber.x = scoreText.width + 5;//placement
scoreNumber.textColor = 0xFF0000FF;//color of text
addEventListener(Event.ENTER_FRAME, checkScore);
}
public function checkScore(e:Event):void {
scoreNumber.text="Your score is: "+scoreString
}
.ral:cr
June 16th, 2009, 05:15 PM
why to waste resources with enterframe if he can update the score in texfield immediately after updates the score value?
tic
June 16th, 2009, 05:19 PM
why to waste resources with enterframe if he can update the score in texfield immediately after updates the score value?
Seeing how he mentioned that, that didnt work for him.
This is a alternative option
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.