4 Replies Latest reply on Aug 15, 2007 7:47 PM by Peter Flynn (Adobe)

    how do you compile and test Actionscript 3.0 class in Flex2?

      I'm a Actionscript programmer for years, but very new to Flex. For my componey want to use some advantages brought by AS3, I desided to use Flex builder to work with AS3 and build classes and swf files. After I installed Flex builder, I find that it is a big trouble to compile and test Actionscript 3.0 class.

      First, it's not like Java or MTASC which calls main function. Flex seems to "new" the class instead, and even worse, it always "new" the main class in the project, event the run menu has changed it's label to the current class. which means if I want to test a simple Class, I need to write a constructor for test only and set it as main class.

      So I tried to write mxml files, althought I don't want to mostly, because most of time, I only want to test one Class. And a another problem comes out: I cannot put mxml files in a subdirectory, because Flex does not build subdirectory in bin directory, so it cannot find the template html file.

      I'm wondering how do you guys compile and test your AS3 Class with Flex, help me please...
        • 1. Re: how do you compile and test Actionscript 3.0 class in Flex2?
          ntsiii Level 3
          It seems that I always have an active application that I am working on to test AS components, and have never had problem.

          Tracy
          • 2. Re: how do you compile and test Actionscript 3.0 class in Flex2?
            Chekote
            You can't compile an AS3.0 class file without an MXML file. You need at least one MXML file that either import and instantiates, or extends an AS3.0 file to "get the ball rolling".
            • 3. Re: how do you compile and test Actionscript 3.0 class in Flex2?
              jmryan
              You can compile AS3 classes, esp. if you create an Actionscript project instead of a Flex project. The important thing is to make sure whatever you have set as your "Main application", whether it be an MXML or Actionscript class, somewhere down the line has a variable of the type of class you want to use.

              You may want to look at using FlexUnit to do your Actionscript testing. "FlexUnit" is a bit of a misnomer as it's specifically designed to test Actionscript inside of Flex.
              • 4. Re: how do you compile and test Actionscript 3.0 class in Flex2?
                Peter Flynn (Adobe) Adobe Employee
                A few things that might help:

                - If you don't need to use any Flex UI components, you can create a plain ActionScript project in Flex Builder and have your main application itself be an AS file, with no MXML involved. It think this is what you referred to originally, but just wanted to clarify Chekote's post.
                - You're right, AS applications work a little differently than Java ones. They are different programming languages, after all :-)
                - Can you describe your problem with the Run menu in more detail? You should be able to chose different applications from within your project to run. If you are using FB Standalone, the default action of the Run button will change depending on what editor tab is current, but this should be reflected by the button's tooltip.
                - MXML applications cannot be put in a subdirectory. You should be able to put other MXML files (custom components) in subdirectories of your source root, however.

                - Peter