How can I address a text field created in Flash (lets say its instance name is mytextfield) from an external class?
-
Can you check this question here : http://stackoverflow.com/questions/7280203/how-do-i-access-a-movieclip-on-the-stage-using-as3-class. See if it helps. – Gurtej Singh Mar 30 '17 at 17:18
-
This will work if your class extends a MovieClip, otherwise you just need to pass the textField reference to your class – Philarmon Mar 30 '17 at 22:11
2 Answers
I don't mean to sound patronizing, I just answering this way in case anyone else may need this information. First if you're working within actionscript 3, When you create a text box you need to make sure that you Embed… the font, unless the characters familie's name begins with an underscore, as in _sans. Second from within the Font Embedding dialogue, you want to make sure you select the Character ranges: option and select the glyphs you're going to need. Not embedding is a mistake many of my students make, even though you may have the actionscript setup right, without the embedded characters nothing will show up.
If it's a click event you want, from within the MovieClip that modifies the field created mytextfield outside itself, the actionscript would looklike this:
this.addEventListener(MouseEvent.CLICK, clickEvent);
function clickEvent(event: MouseEvent): void {
Object(this.parent).mytextfield.text = "hello world"; // Relative
}
or this will work too:
this.addEventListener(MouseEvent.CLICK, clickEvent);
function clickEvent(event: MouseEvent): void {
Object(root).mytextfield.text = "hello world"; // Absolute
}
For those of you who are new to all of this, you need to remember that the text box only receives text information. That means that if you're using any type of a number, you'll have to convert it into a string. This will do the job, String().
this.addEventListener(MouseEvent.CLICK, clickEvent);
function clickEvent(event: MouseEvent): void {
Object(root).mytextfield.text = String(123); // Absolute
}
Hope that helps.

- 40
- 3
you could make it a static public var. That might work.
access it by using myClassName.myTextfield
If not you could also try registering it so you can retrieve it in another class. This 100% works.