Skip to main content
Inspiring
May 31, 2007
Answered

Change text value of TextField on Stage

  • May 31, 2007
  • 11 replies
  • 1302 views
I have created a dynamic textfield on Stage without any instance name. In AS file i want to change the text value but unable to do so. Can we do it in this way.??
This topic has been closed for replies.
Correct answer kglad
cast your display object as a textfield:

11 replies

kglad
Community Expert
Community Expert
June 4, 2007
you're welcome.
kglad
Community Expert
Community Expert
June 4, 2007
i just tested it and it works without problem.
Inspiring
June 4, 2007
Oops sorry that was a silly mistake of not importing the package.

It worked... Thanks a lot for your help

kglad
Community Expert
Community Expert
June 2, 2007
do you need to use import flash.text.TextField in your class file?
Inspiring
June 1, 2007
@Raymond
Same error is coming

1119: Access of possibly undefined property text through a reference with static type flash.display:DisplayObject.


kglad i didn't get it. I have make it to work only after putting it inside MC in library and then attaching it. but if the textfied is on Stage it is not working
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 1, 2007
cast your display object as a textfield:

Inspiring
June 2, 2007
Same error is coming

Location Test.as Line 6
Description 1180: Call to a possibly undefined method TextField.\
Source TextField(this.getChildAt(0)).text = "Nitin"
kglad
Community Expert
Community Expert
June 1, 2007
then you should be extending the movieclip class.
Inspiring
June 1, 2007
I simply use DocumentClass as Test and using this.getChildAt(0) returns the object of TextField on Stage.
kglad
Community Expert
Community Expert
May 31, 2007
how do you associate a textfield with Test?
Inspiring
May 31, 2007
Thanks i will try it.
Inspiring
May 31, 2007
It's a timing issue. Wait for the ADDED event to fire:

package {
import flash.display.Sprite;
import flash.events.*;

public class Test extends Sprite {

public function Test() {
trace(this.getChildAt(0).name);
addEventListener(Event.ADDED, addedHandler);
}
public function addedHandler(event.Event) {
this.getChildAt(0).text = "Nitin";
}
}
}