Search code examples
flashactionscript-3flash-cs4

how to handle multiple game modes in actionscript 3 - flash


I'm new to actionscript flash 3.0. Anyways, i have written code for one whole game level including the character. Is it now possible to create a class, and when i press for e.g. 'Level 1' the first level starts?(create an object of the class) When i press quit, to unload the whole level. How is this possible in flash? are there any tutorials? thanks.


Solution

  • The joys of OOP. ANY time you code in an object orientated language you need to develop your classes for re-usability. After all that is one of the main goals for OOP design. You did not post any code so I am going to assume you wrote your game in a procedural way and did not use and classes besides the base classes supplied to you by flash packages.

    As an example Since we are talking about games think of a bullet. You can make a bullet class that will control all aspects of any single bullet( from hitting a target to its trajectory to flying off into space. so when the user fires a round you would create a new instance of the bullet and assign an event listener to it for something like "HIT" of course you would have to dispatch the event in the bullet class, but at this point the only think you would need to worry about is if a hit event happened, the bullet class takes care of everything else.
    Basically, as you can see doing it this way encapsulates any action with bullet aside from the HIT event.

    An other example would be a Button. This class comes with the flash libraries and I am sure you have used it before. Drag a button onto stage add an eventlistener make an onclick function and you are done. None of the internal methods of the Button class need to be played with, it's all encapsulated nicely for you.
    Kirupa is always a good place to learn LINK
    Be prepared to rewriting your entire game for this change. Porting procedural code into classes can be a hair pulled experience