6 Replies Latest reply on Sep 21, 2007 10:26 AM by levancho

    calling actionscript file package classes

    MR_Fang
      I have composed a simple actionscript class called "test.as" under this directory \project\as\test\.
      The test.as class is packaged as "package as.test".

      In my main flex file main.mxml, how can reference this test.as class without getting a complied error by not packaging up the package as "package project.as.test"? Any approaches to this problem? I know in java it can be done with Jar package.




        • 1. Re: calling actionscript file package classes
          Senor_Roberto
          Your main.mxml file should be in the root of your source tree:

          /project/main.mxml
          /project/as/test/test.as

          When you compile mxmlc uses the path of the file you're compiling as the root of the include path. So in main.mxml you can refer to your class using import as.test.test.as.

          I'm not sure how this relates to JAR files (maybe I am misunderstanding your question?). If you want to create a standalone library (like a JAR) you can compile a library component using the compc compiler.










          • 2. Re: calling actionscript file package classes
            MR_Fang Level 1
            Sorry if I didn't communicate clear on my original question.
            Let me reintegrate my question on the actionscript package. If I created an actionscript file and main.mxml under these directory,

            \project\as\utils\features\test.as
            \project\main.mxml

            and in the test.as, I packaged the file as strictly below
            package utils.features
            { public class Test.{...blab...blab...}}

            Is it possible to reference the "test.as" class without explicitly using package directory as package as.utils.features?
            Will this create a problem when I call this class from the "main.mxml"? How do I manage to compile and use this type of package structure?

            Thanks,
            Fang
            • 3. Re: calling actionscript file package classes
              ntsiii Level 3
              You can add a folder to the list of sources the compiler looks at. It is in the Project, Properties in flexBuilder, don't know the flex.config syntax.

              Tracy
              • 4. Re: calling actionscript file package classes
                Omar_Gonzalez Level 1
                quote:

                Originally posted by: MR Fang
                Sorry if I didn't communicate clear on my original question.
                Let me reintegrate my question on the actionscript package. If I created an actionscript file and main.mxml under these directory,

                \project\as\utils\features\test.as
                \project\main.mxml

                and in the test.as, I packaged the file as strictly below
                package utils.features
                { public class Test.{...blab...blab...}}

                Is it possible to reference the "test.as" class without explicitly using package directory as package as.utils.features?
                Will this create a problem when I call this class from the "main.mxml"? How do I manage to compile and use this type of package structure?

                Thanks,
                Fang


                in your MXML you would say...

                <mx:Script>
                <CDATA....

                import project.as.utils.features.test;

                private var myClassInstance:test = new test();

                ]]>
                </mx:Script>

                or... if test.as extended something like a <mx:Button/> you can do something like this..

                In your MXML, in the Application tag add...

                <mx:Application ... xmlns:myCustomNS="project.as.utils.features.*" >
                <myCustomNS:test />
                </mx:Application>



                • 5. Re: calling actionscript file package classes
                  MR_Fang Level 1
                  Thanks for all these great answers. What is the approach if the Actionscript packages/classes are not part of the main.mxml directory structure, the AS package is an external directory?

                  For example: \external\as\utils\features\test.as
                  \project\main.mxml

                  My question are,
                  If I package up the test.as file as package utils.featurse ,
                  and imported to my main.mxml script also as import utils.features.* ,

                  - How do I compile this type of setup with an external AS package, in Flex builder IDE and mxmlc.exe command line prompt?
                  - Do I need to specify an external AS reference path variable for this type of setup??


                  Thanks,
                  Fang
                  • 6. calling actionscript file package classes
                    levancho Level 3
                    your package as files etc .. must be archived in a acceptable package format which is swc(renamed zip same as jar for java) and compiler arguments (if you do it through builder gui get genearetd automaticaly in actionscriptProperties file like this :

                    <libraryPathEntry kind="3" linkType="1" path="path/to/your/package.swc" useDefaultLinkType="false"/>

                    if you compile through command line just pass these arguments with - prefix and this should work as well.