4 Replies Latest reply on Nov 29, 2006 1:29 PM by ntsiii

    Component Question

    AonSao Level 1
      Could anyone provide a simple example of using an ActionScript class as the default application in Flex... but still using Flex components? Or is this not possible?
        • 1. Re: Component Question
          peterent Level 2
          I'm not sure why you would want to do that, but you should be able to create a class which extends Application. Then override createChildren and create your components there - if you have MXML components, just treat them like any class and use the new operator. Just remember to give them width and height because they'll default to zero. You should also override measure and updateDisplayList to measure and position the component children.
          • 2. Component Question
            AonSao Level 1
            Thank you ^_^ I got that working!

            I'm a bit new to this though... you mentioned that you don't know why anyone would want to do that. What is the easier way to handle this? I've been messing around with controlling program flow from an MXML application file... but I just haven't been able to get my actionscript display objects onto the stage. I'm animating sprites, shapes, and movie clips and I can't figure out how to get both those and MXML components on the stage at the same time.
            • 3. Re: Component Question
              peterent Level 2
              I meant I didn't understand why you would not want use an MXML file as your Application file? It would be easier to work with and you wouldn't have to override any functions.
              • 4. Re: Component Question
                ntsiii Level 3
                Per Gordon Smith, on this subject:

                "Sorry, although we've made it easy to write components in either MXML or AS3, we haven't done the same with Application. If you are a newbie you should start out with <mx:Application> in MXML. You can then use AS3 for all your components if you really want to. I hope we can make this better in a future release.

                What's going on is that when the MXML compiler compiles an <mx:Application> it autogenerates code to set up a lot of stuff such as the default CSS type selectors that various components like Button depend on. These aren't getting set up when you simply extend Application as an AS3 class. When Button calls getStyle() to find out what it's skin class should be, it's getting a null Clas reference.

                Once you are no longer a newbie, you can use mxmlc's -keep-generated-actionscript option to see all the generated code, and set this stuff up yourself it you insist. But I really don't understand why some developers like AS3 so much better tham MXML. Would you write a web app all in JS and no HTML?"

                So it is a lot of work to avoid basing the app on mx:Application. Be sure you have a good reason.