7 Replies Latest reply on Nov 5, 2011 7:03 AM by McbainGames11

    Document Class Help.

    McbainGames11 Level 2



      I have a class called 'Main' that runs as document class but the class i only want to work on a few frames. I can't use MyClass:Classname  = new Classname(); because it doesn't work the same.


      What happened with it being document class is that all my game functions happened on all of the frames when i want the games functions to happen on certain frames.


      So my question is, how do you get a class to work the same a document class for specific frames?


      Is there a way to import the class 'Main' that will work the same as document class using MyClass:Main  = new Main();? Because from my knowledge that is for objects.



        • 1. Re: Document Class Help.
          Peter Celuch Level 4

          Document class controls behaviour of the whole swf file (the main timeline). You can't just assign a class for specific frames, flash just doesn't work that way.

          If by "game functions" you mean mouse and keyboard listeners, you should define functions activateGameControls() and deactivateGameControls() in which you add or remove eventListeners. Then, when you leave your "game frames" you just call deactivateGameControls() function.

          • 2. Re: Document Class Help.
            Peter Celuch Level 4

            Another approach is to encapsulate all of your game logic into single MovieClip (instead of root of the document) and assigning it a class (library -> rightclick on the symbol -> properties).

            In Main.as you'll have a reference to you game:


            var game:Game = getChildByName("mc_game") as Game;


            and then you can create activation / deactivation functions in the Game class and call it from the Document class.


            1 person found this helpful
            • 3. Re: Document Class Help.
              McbainGames11 Level 2

              I like this first idea. So when you add class as document class then i can access each function through timeline?


              And How would i deactivate a function that starts off a activated, because i have made my class to activate straight away so the question is how would i deactivate/stop a function that i have already activated in the class?


              ^ ^ Confusing Explanation haha. Hope you understand.



              • 4. Re: Document Class Help.
                Peter Celuch Level 4

                Yes, you can call the Document class's functions from its timeline.


                I guess that by "start activated" and "activate straight away" you mean that you placed addEventListener calls into the Document class's constructor (function Main() {}), right?

                You should wrap those calls into the activateGameControls() function and call it from constructor:


                public function Main() {


                You can removeEventListener as many times as you want, it it's already removed, the call will be ignored - no errors.

                1 person found this helpful
                • 5. Re: Document Class Help.
                  McbainGames11 Level 2

                  What i will do since my main activates everything straight away which i only want on game levels i will make a function called activateGameControls(); and call it from Main();


                  This method gives good control thanks for your help, Havn't had time to test this but i will go ahead and say this is solved because sounds simple enough and should work

                  • 6. Re: Document Class Help.
                    Peter Celuch Level 4

                    Cool. Let me know if there's a problem.

                    Good luck.

                    • 7. Re: Document Class Help.
                      McbainGames11 Level 2

                      Worked, easy few lines of code of basically copy n pasting functions


                      Problem Solved.