6 Replies Latest reply on Jun 14, 2007 11:43 AM by a.neko®

    Flex ActionScript projects | Flex components

    a.neko®
      Is it possible to create Flex 3 ActionScript projects using Flex 3 components/containers?

      The aim would be to obtain the same result as with MXML, only using exclusively ActionScript classes in the entire project. So far, using Flex Builder 2.0.1, I've tried to create an ActionScript project with the main class extending any of the mx.core or mx.containers components. I've replicated the same project's source/SWC settings as in an MXML project, but permanently got errors while compiling.
        • 1. Re: Flex ActionScript projects | Flex components
          Gaurav J Adobe Employee
          Yes it is possible with Flex 3 also.

          Can you provide details of the compilation errors, please?
          • 2. Re: Flex ActionScript projects | Flex components
            a.neko® Level 1
            Well... I've tried it many times in many ways with Flex 2.0.x Builder, and got all sorts of results - except the expected one.

            Now - what I've done is:


            Created an ActionScript project ( DevelopmentAS - DevelopmentAS.as)

            In Project | Properties | ActionScript Build Path | Library Path:
            - added SWC folder: {FLEX_BUILDER_INSTALL_DIRECTORY}/sdks/moxie /frameworks/libs

            Invoked Project | Build All

            Modified the DevelopmentAS class as follows:
            package {
            import mx.core.Application;
            public class DevelopmentAS extends Application {
            public function DevelopmentAS() {
            super();
            }}}

            Launched, and got:
            TypeError: Error #1009: Cannot access a property or method of a null object reference.at mx.core::UIComponent/getStyle()[E:\dev\flex_3_beta1\sdk\frameworks\projects\framework\src ;mx\core;UIComponent.as:7262]
            etc...

            I've used mx.core.Application, but it's the same thing with extending any mx.core, mx.containers, mx controls etc... component.


            Otherwise, when modifying DevelopmentAS class as follows:
            package {
            import mx.core.UIComponent;
            public class DevelopmentAS extends UIComponent {
            public function DevelopmentAS() {
            }}}

            Launched and got:
            TypeError: Error #1007: Instantiation attempted on a non-constructor. at mx.resources::ResourceManager$/getInstance()[E:\dev\flex_3_beta1\sdk\frameworks\projects\ framework\src;mx\resources;ResourceManager.as:78]
            etc...


            Otherwise, when modifying DevelopmentAS class as follows:
            package {
            import flash.display.Sprite;
            import mx.controls.Button;
            public class DevelopmentAS extends Sprite {
            public function DevelopmentAS() {
            var buttonComponent:Button=new Button();
            }}}

            Launched and got:
            TypeError: Error #1007: Instantiation attempted on a non-constructor. at mx.resources::ResourceManager$/getInstance()[E:\dev\flex_3_beta1\sdk\frameworks\projects\ framework\src;mx\resources;ResourceManager.as:78]
            etc...

            ...which - if I remember correctly - is the same error I constantly obtained when trying something similar with Flex 2.0.x.
            • 3. Re: Flex ActionScript projects | Flex components
              Gaurav J Adobe Employee
              The errors that you are getting are not compile errors but are runtime errors. You are getting these errors because extending the Flex Components in actionscript require more code than what you currently have, MXML take care of that behind the scenes.

              To see the action script code that is generated when you write a simple mxml Button Application use the option -keep-generated-actionscript=true duing compilation and the generated action script will be stored in a folder called generated.
              • 4. Re: Flex ActionScript projects | Flex components
                a.neko® Level 1
                Will do as you say - thanks a lot.
                • 5. Re: Flex ActionScript projects | Flex components
                  Gaurav J Adobe Employee
                  If your objective is to override some behaviour of how mxml components behave, you should also look into code-behind pattern.

                  The following blog from Ted gives a quick overview.

                  http://www.onflex.org/ted/2007/02/code-behind-in-flex-2.php
                  • 6. Flex ActionScript projects | Flex components
                    a.neko® Level 1
                    Great resource!

                    I do all of my coding in ActionScript, so my aim was to simply avoid MXML. It seems I'll have to spend some more time understanding a few things in order to achieve it...

                    However, code-behind solution should result very useful in a project I currently work on.

                    Thanks again.