3 Replies Latest reply on Oct 12, 2007 11:20 AM by ebelair

    Cannot create component in external source path

      I am creating custom components for my Flex application (FB3 Beta 2) and read in a blog that it would be preferable to keep the components in a separate location from the application.

      That seems to make a lot of sense to me as I then can reuse my components in other applications as well.

      So I went ahead and created a folder called "MyComps" in the file system and added it to the Flex Build Path (via the Properties of the Flex application). => a new entry in the application's Flex Navigator appears: "[source path] MyComps"

      I then wanted to create a new ActionScript class located in that package but I run into a problem with the package name:
      "ActionScript package names must start with a letter, underscore (_), or dollar sign ($)."

      I tried to create the ActionScript class via the File\New\ActionScript Class "New ActionScript Class" dialog. When I browse for the Package and select from the list the "[source path] MyComps" package, I obviously break the package naming convention.

      Question: What do I need to do to remedy this problem?

      Thank you,
        • 1. Re: Cannot create component in external source path
          Don't ActionScript classes need to part of a package in a library - i.e. a SWC file?

          Either way, to create reusable classes, you can create a Flex Library project, which, when compiled, will create a SWC file.


          1. Create a Flex Library Project. Give it any name you like (i.e. "myLibs"), and it will create a directory in your Workspace with that name.
          2. Within the Flex Library Project, create a new folder, for each package you want to create. For instance, if you want to create package of formatters, you could create a folder named "formatters".
          3. Within the package/folder, create a new ActionScript class.

          I have attached an example of a class I created. This file is located at {Workspace}/myLibs/formatters/formatter.as, where the name of the Flex Library Package is "myLibs", the name of the package is "formatters", and the name of the class is "formatter". I also have two other classes in this package that are herein referenced as "currencyFormat" and "decimalFormat".

          Once the Flex Library is compiled, you can then add it to any Flex Project in "Properties > Flex Build Path > Library path". This allows for reusability, and keeps your [functional] classes separate from your [visual] components.

          I hope that helps.


          • 2. Re: Cannot create component in external source path
            dnii Level 1
            Oops, thanks for setting me on the right path.

            I was so used to being able to just add a folder as a package and work from there that I skipped the thought process about what I actually wanted to accomplish: a reusable component library.

            But your question and nice example got me straightened out and I got everything working and squared away.

            Thanks for your time.
            • 3. Re: Cannot create component in external source path
              ebelair Level 1
              Awesome. I come from a ColdFusion/SQL background, and I've only been writing ActionScript and Flex for about 2 months now, so I'm no expert, but I've been making it a point to learn how to reuse code in Flex, because I'm tired of being brought into projects that are just a mess. Hopefully I'm getting off on the right foot. Good luck!