3 Replies Latest reply on Aug 24, 2006 11:13 AM by Newsgroup_User

    True OO GUI Creation Possible?

    davefc
      Hello --

      I am trying to create a complex, multi-window application in Flash without using the GUI to drag and parameterize components. I would like to build a Swing/AWT-like application with all my code in .AS class files, with maybe a bootstrap #include file in the first frame of the main (otherwise emtpy) FLA. MovieClip.createEmptyMovieClip() seems like a promising start as I can then manipulate an empty clip and its parent with MovieClip methods. However, there are no methods for adding all types of UI Components to the MovieClip -- like java.awt.Container, for example.

      Is there any way to programmatically add all types of Components (with behavior) to a UI Container without having to visually drag things into the Library through the GUI and create instances there? MovieClip does not seem to have calls like addComponent() and setLayoutManager() needed for a true OO approach. UIObject and UIComponent are more promising, but it is still not clear if and how to build control-filled windows completely via .AS files, using a blank base FLA file.

      Is this possible in Flash? Thanks for your help!
        • 1. Re: True OO GUI Creation Possible?
          Level 7
          davefc,

          > Is there any way to programmatically add all types of
          > Components (with behavior) to a UI Container without
          > having to visually drag things into the Library through the
          > GUI and create instances there?

          You betcha.

          > MovieClip does not seem to have calls like addComponent()
          > and setLayoutManager() needed for a true OO approach.
          > UIObject and UIComponent are more promising, but it is still
          > not clear if and how to build control-filled windows completely
          > via .AS files, using a blank base FLA file.

          You can, and UIObject and UIComponent are where you'll want to focus
          (look for createClassObject() method). As an aside, note that all the
          Components ultimately inherit from MovieClip anyway.

          > Is this possible in Flash? Thanks for your help!

          It is possible with Flash, but for the kind of approach you seem to be
          taking, you're much more likely to *enjoy* doing this with Flex.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: True OO GUI Creation Possible?
            davefc Level 1
            Thanks David. I appreciate your help. But, how do I bootstrap the process?

            Say, I have a MovieClip instance handle. How do I then associate an intial UIComponent with it so I can then take advantage of the methods on UIComponent/UIObject which will allow me to create child components? There is a chicken and egg issue here as MovieClip does not have an addUIComponent()-like method isn't there?

            For example, from the documentation:

            import mx.controls.Button;
            XXX.createClassObject(Button,"button2",5,{label:"Test Button"});

            XXX can't be a MovieClip returned from createEmptyMovieClip() as that would be a downcast to UIObject. So, how do I go from an empty MovieClip to an empty MovieClip with some UIObject inside it that I can then use createClassObject() on? Am I just confused, or do you see my problem?

            I thought of dragging a Window instance onto the stage, making it available for ActionScript, and then accessing it through the parent MovieClip. This is pretty clunky, and the Window has a title bar and other behavior I do not need.

            A couple lines of source that show me how to go from an empty MovieClip to one with, say, two buttons and a dropdown list on it would be great.... :-)

            Thanks again!
            • 3. Re: True OO GUI Creation Possible?
              Level 7
              davefc,

              > Say, I have a MovieClip instance handle. How do I then
              > associate an intial UIComponent with it so I can then take
              > advantage of the methods on UIComponent/UIObject
              > which will allow me to create child components?

              Aha. I gotcha. You don't. It's a bit quirky with AS2. I'm still
              learning AS3, which is *way* different. I recommend you take a look at
              that, because you'll be much more familiar with it coming from a Java
              background.

              Meanwhile, here's way quickie AS2 snippet to put a Button component to
              the Stage.

              import mx.controls.Button;
              var b:Button = createClassObject(Button, "button2", 5, {label:"Test
              Button"});
              b.move(100, 200);
              // etc. -- b is a Button instance, so you have the whole
              // inheritance tree at your disposal


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."