Skip to main content
Jon Chambers
Inspiring
December 8, 2016
Answered

If not a document class, then what?

  • December 8, 2016
  • 2 replies
  • 636 views

I started creating a game, and did a lot of work regarding handling of player controls in the document class. Now, I added a scene and a menu. Menu navigation requires a completely different control scheme, and my old script keeps calling useless functions that just waste processor time at best, or create name conflicts and bugs at worst.

My first instinct is to copy/paste everything into frame 1 of the scene that isn't a menu, but isn't there a better way? How do I stop my document script from loading until the game has begun?

    This topic has been closed for replies.
    Correct answer Colin Holgate

    When you have a movieclip in the library it can be set to export for actionscript, and you would put in the location of an external Class file. If you made your current scene be a movieclip, and in the library you get the properties for the movieclip, in Advanced view you would select the export for actionscript box, and for the Class file you would enter the location of your current document class. Then you could place that movieclip on the stage and start with a new document class for the FLA.

    It would make sense to change some names though. For example, if your FLA is named MyGame, and your current document class is MyGame.as, you probably want to keep that the same, for the new fresh document class. So, for the new movieclip you would change the two places that say MyClass to perhaps MyClassScene1, and save that copy of the file as MyClassScene1.as. In the library movieclip properties I mentioned, you would use MyClassScene1 as the class name.

    Finally, in the new FLA document class you no doubt will want to keep some of the global level functions, and remove all the scene specific functions, and in the duplicate renamed MyClassScene1.as you would keep all the scene specific functions and delete any of the global functions that will now be handled by the new document class.

    2 replies

    Jon Chambers
    Inspiring
    December 8, 2016

    Nice work again Colin. My brain is too sleepy right now to be able to follow those instructions, but I do think I understand.

    So Ctrl + A then F8 to turn everything into a movie clip?

    Colin Holgate
    Inspiring
    December 8, 2016

    If only it was that simple! But it's not much harder. Select all of your layers, in the layers column part of the timeline. Right-click and Copy Layers. In the library right-click and do New Symbol, make it a movieclip, with a sensible name. After you've done that you're now looking at the timeline of the movieclip. Right-click in the layers column and do a Paste Layers.

    Back in the main timeline you should now be able to delete the original layers, and drag the new movieclip out onto the stage. Then try to follow what I was saying before about the class files.

    Jon Chambers
    Inspiring
    December 8, 2016

    Ah good. Thanks. Now it's a lot more Dummies-Guide-To. I'll try it tomorrow, though if you can see anything in there that could be dumbed down further, it might be a big help.

    kglad
    Community Expert
    Community Expert
    December 8, 2016

    there are several 'tried and true' to ways to organize classes.  you should use one of those ways to organize your classes.

    everyone has their favorites.  mine is to use the document class to add and remove other class members (or instances) to the stage and handle any global things like background sound that permeates the app/game.

    each class member added/removed by the document class would have its own class file that handles its internal workings.  roughly, instead of changing frames to change what's displayed, different class members are added and removed.

    often the first class member added is an intro class member (which explains how to navigate) or menu class member (with the navigation).

    Jon Chambers
    Inspiring
    December 8, 2016

    I'm not asking how to start a project, but how to salvage one. All I want to do is create a new document class script and have the current document class script called on scene 2. I'm asking literally, what I should click and/or type to make this happen.

    Colin Holgate
    Colin HolgateCorrect answer
    Inspiring
    December 8, 2016

    When you have a movieclip in the library it can be set to export for actionscript, and you would put in the location of an external Class file. If you made your current scene be a movieclip, and in the library you get the properties for the movieclip, in Advanced view you would select the export for actionscript box, and for the Class file you would enter the location of your current document class. Then you could place that movieclip on the stage and start with a new document class for the FLA.

    It would make sense to change some names though. For example, if your FLA is named MyGame, and your current document class is MyGame.as, you probably want to keep that the same, for the new fresh document class. So, for the new movieclip you would change the two places that say MyClass to perhaps MyClassScene1, and save that copy of the file as MyClassScene1.as. In the library movieclip properties I mentioned, you would use MyClassScene1 as the class name.

    Finally, in the new FLA document class you no doubt will want to keep some of the global level functions, and remove all the scene specific functions, and in the duplicate renamed MyClassScene1.as you would keep all the scene specific functions and delete any of the global functions that will now be handled by the new document class.