How can I take a simple counter and I want to load the current count into a textbox?
My code:
count1 = new Timer(count);
count1.addEventListener(TimerEvent.TIMER,stopWatch);
count1.start();
private function stopWatch(event:TimerEvent):void{
var myTextBox:TextField = new TextField();
myTextBox.text = count1.currentCount;
addChild(myTextBox);
}
Resulting error:
1067: Implicit coercion of a value of type int to an unrelated type String.
You are getting this error because you are assigning an
intto the.textfield. It will only accept astringand will not implicitly cast it. Use thetoStringmethod ofintsupplied to you by the baseObjectclass.See also, this answer on the same subject.
Update, regarding comment:
I would avoid using
addChildwhen the event fires. AssumingstopWatchis called more than once, the posted code will add a newTextFieldevery time. Instead, just create it once, but set the.textfield every time the event fires.