3 Replies Latest reply on Jun 25, 2007 6:03 PM by MotionMaker

    import main in class

    tag_digital
      I'm wondering if this would work and if it does if its bad programming practice or not. I am trying to do things right and don't want to develop bad habbits...anyway if I have a class with a button and I want that button to call a function in main (the main document class) could I import main to that class so it has access in a handler to call the function in main? I'm trying to figure out a way to have button panels (a message I left here earlier) control different aspects of a game, ie..startOver, Quit, etc...I know I can create the buttons in main and it will work but I want to encapsulate them in functional 'button' panels. Since the main functionally of the game lies in 'main' how can I encapulate the button panel(s) with the appropreate buttons to control functionallity in main? I'm not looking for someone to give me the code...just someone with more Class knowledge to steer me in the right direction. THANKS!
        • 1. Re: import main in class
          MotionMaker Level 1
          However it appears you are in AS3. You can have a document class with the properties window or import the document class and instantiate. At this point best I can differentiate between the two is the latter allows passing parameters to the constructor.

          In any case, you should have the document class instantiate the navigation classes and add to the display structure you have designed.
          • 2. Re: import main in class
            tag_digital Level 1
            Thanks Lon...its all starting to make sense..(finally:)) At this point I'm thinking I should start to embrace the eventDispatcher. Since I want my buttons to be encapuslated with the panels object but control objects instantiated in main. I guess writting the eventHander functions in the panel class doesn't really make much since the objects they will be manipulating will be objects instantiated in main. I'm thinking now to have the buttons trigger an eventDispatcher and have the handler functions in main listen for them. If I'm understanding everything correctly this seems to be at least one way to do it.

            Thanks Again.
            • 3. Re: import main in class
              MotionMaker Level 1
              I was kicking this around a few weeks back. Here are the scraps of code I had. However got switched back to Flex so ... Actually I was doing this in Flex as an Actionscript project. But it should kick in Flash CS3.