I'm trying to figure out the best way to deal with writing multiple GUI windows using Flash Components. I thought the best way to handle this was to use a layer for each window that I want, and simply hide/show the layer I want for the window. It would be preferred to not use actionscript alone.
Since each layer holds these GUI components, I place the actionscript code dealing with them in Frame 1 of each layer. This keeps all the GUI code in one place and avoids me having every component declared and handled within the main stage class.
My problem though is a scoping issue. The main stage class can access all the components from its class that resid开发者_开发问答e on these layers, but the frame layer "frame 1" actionscript doesn't seem to. I would like to be able to call methods on the main stage class from within the frame 1 actionscript code on the layer. It doesn't seem to work, and I've even tried casting the stage reference to the reference of my class. Not sure if this was stupid to try, but just trying to figure out a way.
If someone has a better way to go about handling this, please let me know. My fallback plan is to either avoid dragging and dropping the components on the stage and instead use actionscript alone, then organize these components into their own classes, or use event listeners on the main stage for all the components, which would bloat the stage class with all that GUI code.
Thanks!
First of all, you will have some trouble with your approach of using a layer for each window. Sadly, the layers are something that is only used in the flash authoring environment, the code doesn’t have any way of knowing what is in what layer, so you will have no way (as far as I know) to hide the contents of each layer the way you intend.
A couple of alternatives is that:
- You put the components of each window inside a movie clip, this way you can make visible or invisible that single movieclip, one for each window you want. It is more or less the same youy want with layers, but using a movieclip containing each window.
- Instead of using layers, use frames. Put all your components for the first window in frame 1, the components of the next in frame 2. This way you can control which window you are at by moving the playhead.
About the scope errors you have, can you give more details? What errors if flash printing?
精彩评论