how do I make non-document-class classes 'aware' of stage components in Flash AS3?

后端 未结 5 527
余生分开走
余生分开走 2021-01-28 05:56

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

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 06:53

    Are myTA and myTI actually on the stage at author time or are the added dynamically?

    In the first case, just add an instance name to each. Then add a variable to each class

    var main_mc : Main = root as Main;

    You can then access the instances via main_mc.myTA and main_mc.myTI (assuming those are the instances names you chose) and everything should be type-safe.

    In the dynamic case, just make sure you save off references in the main class to each as you add them.

    Another option is to have classes for myTA and myTI send an event in their constructor to announce their existence. The main class can then listen for these and register the references.

    To be honest, though, you are mixing up your display with your logic. Read up on MVC and PureMVC in particular. With a good design, everything can be handled by messages, and the instances don't need direct references to each other. IIRC, Moock's AS3 book has a chapter on MVC (but it could be his AS2 book).

提交回复
热议问题