Reputation: 15484
i have a dynamic text on my scene called testtext, in the accions i can show a text simple by testtext.text = "my content";
But now i want to do this from a class, if i copy directly the instruccion like i do normaly it doest work. What i need to do? Thanks!
Upvotes: 0
Views: 113
Reputation: 1165
your class is self contained and not aware of the outside world. You will need to create a function that you can feed it the textfield name so it can then target it.
so from inside your class create a public function like this:
public var myTextField:TextField;
public function setTextTarget(tf:TextField):void
{
myTextField = tf;
}
public function updateText(msg:String):void
{
myTextField.text = msg;
}
private function randomFunction():void
{
// update the textfield from an internal function
myTextField.text = "text here"
}
So in your FLA file where you have imported your class it will look something like this:
var myClass:ClassName = new ClassName;
myClass.setTextTarget(TextFieldName);
myClass.updateText("text here");
Upvotes: 3