Use swc in flex

Scenario 1: You need to compile ActionScript code as a reusable component in Flex Builder.

Solutions: Follow the steps (FB plugin v3):

Step 1. Compile swc. First you will need to create a new “Flex Library Project”. Then copy all the actionscript code into the top folder of your project file, retaining the package/namespace structure (fig. 1)

The file structure and xml manifest file in Flex Library Project

In “src” folder, you would need a xml-manifest.xml file where you declare the class and id (optional, default to the class name anyways) (fig 1). Thirdly, you would need to define your namespace for the class that’s going to be referenced in MXML (or Flash?) like so: In the AS class fine, inside the class definition, just like the way as you declare a variable, add “public namespace fc;” (substitue “fc” with whatever your choice of namespace). If you’ve enabled “build automatically” (under “Project” menu command), FB will instantaneously build the deploy files for you the time you save the AS file. The result is the complied .swc file, which you can find in the “bin” folder in your library project.

Step 2. Use swc in your Flex project. You either need to copy the swc file(s) into the library-path folders as defined in your flex-config.xml, or explicitly tell Flex to use the swc you want in your current project. To do so, go to “Project properties”->”Flex Build Path”->”Library Path”->”Add SWC”. You can simply navigate to the swc file in the Flex library project as defined in Step 1. After Flex compiled the project, you can use the component as defined in your ActionScript code. Here is an extract:

<mx:HBox>
<mx:Label text="Search by last name: "/>
<fc:AutoComplete id="lastNameSrchAC" dataProvider="{listInfo}" labelField="lastName"/>
</mx:HBox>

See also: Namespaces in Flex and Soprano

Advertisements

3 Responses to “Use swc in flex”

  1. abhishek Says:

    could u mailed me more examples to use swc and library projects in flex 3 ?
    abhishekchess1@gmail.com

  2. Ellery Says:

    Hi, what’s happen when a dataprovider must be loader from data in the data base, and the result it’s variable.

    the problem it’s bigger when you use a WebService that it’s slow in the response.

    how can do make a fc:autocomplete wait for the result from WS.

    Thank’s and regards

  3. Batul Says:

    hi, i tried changing the namespace to fauto in the class definition. Now when i try to access it as in my project, it gives me the error that prefix for element is not bound. I thought that since the namespace is declared as public, i should not have to assign namespace to url… now if i have to assign it to a url, what should it be? i tried giving the entire path to the manifest.xml, but does not work. Please help me.
    Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: