I am working on a text adventure game which will have at least a few components (a text area for narrative and text input for user input) on the stage at all times. Therefore, I
I think some dependency injection will solve this problem. When you instantiate your Typewriter
class, pass references to myTA
and myTI
. ex:
public function Main{
testTypeWriter(this.myTA, this.myTI);
}
Then your Typewriter
constructor should look like this:
public function TypeWriter(ta:TextArea, ti:TextArea){
this.myTA = ta;
this.myTI = ti;
}
This also has the benefit of making your application less tightly coupled, so for example you can reuse your Typewriter
class with a different text area and text input.
Edit
Some extra info that may help you in the future: you can access stage elements through the root object. But this only works with objects that have been added to the display list. Let's say that Typewriter
represents an object in the display list, you could then access myTA
like this:
MovieClip(root).myTA
(Change MovieClip
to Sprite
if that's what your document class extends).
However, since it seems that Typewriter
does not get added to the display list, I recommend using my first suggestion of dependancy injection.
Also check out this page, it dicusses using CasaLib to access the stage from any object. I personally haven't tried it, so that's why it's at the end here ;-)