Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex Quick Starts /

Packaging components

by Adobe

Adobe logo

Created

22 March 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flex

Requirements

User level

All

Required products

  • Flex (Download trial)

One way to distribute your components to other developers is as MXML or ActionScript files. You set them up in the directory structure that matches the package structure, and you compress them into an archive format such as PKZip. The consumers of your components expand that archive into their development environment and use those components in their applications. The downside to this is that they have the source code and source files for your components, and your components are uncompiled.

The alternative method of distributing components is to package your components as a SWC file or as part of a Runtime Shared Library (RSL). The benefits to doing this include ease-of-deployment, run-time efficiency and security.

A SWC file is an archive file for Flex components. SWC files make it easy to exchange components among Flex developers. You need only exchange a single file, rather than several MXML and ActionScript files, images, and other resource files. Also, the SWF file inside a SWC file is compiled, which means that the code is obfuscated from casual view.

SWC files can contain one or more components and are packaged and expanded with the PKZip archive format. You can open and examine a SWC file by using WinZip, JAR, or another archiving tool. However, you should not manually change the contents of a SWC file, and you should not try to run the SWF file that is in a SWC file outside of a SWC file.

This Quick Start covers the following topics:

  • Creating SWC files
  • Deploying SWC files

Creating SWC files

To create a SWC file with the Flex SDK, use the compc command-line utility in the flex_install_dir/bin directory. The compc utility generates a SWC file from MXML component source files and/or ActionScript component source files.

When you use the compc compiler to create a SWC file, you can include any number of components. When you use components from that SWC file in your Flex applications, the mxmlc compiler includes only those components that are used by your application, and dependent classes, in the final SWF file.

To start, create a folder called QuickStartLibrary. In it, create a folder named components and place the following custom component classes in the components folder.

Example

components/AddressFormAlert.mxml

<?xml version="1.0" encoding="utf-8"?> <!-- components/AddressFormAlert.mxml --> <mx:Form xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:custom="components.*"> <fx:Script> <![CDATA[ import mx.controls.Alert; protected function submitButton_clickHandler(event:MouseEvent):void { // Compose a string to display the contents of the value object to the user. var msg:String = "You submitted the following information: \r"; msg += "Name" + ": " + nameInput.text + "\r"; msg += "Street" + ": " + street.text + "\r"; msg += "City" + ": " + city.text + "\r"; msg += "State/County" + ": " + state.text + "\r"; msg += "Country" + ": " + country.selectedItem + "\r"; // Display the contents of the address form to the user. Alert.show(msg, "Thank you for submitting the form!"); } ]]> </fx:Script> <mx:FormItem label="Name"> <s:TextInput id="nameInput"/> </mx:FormItem> <mx:FormItem label="Street"> <s:TextInput id="street"/> </mx:FormItem> <mx:FormItem label="City"> <s:TextInput id="city"/> </mx:FormItem> <mx:FormItem label="State/County"> <s:TextInput id="state"/> </mx:FormItem> <mx:FormItem label="Country"> <custom:CountryComboBoxSimpleMXML id="country"/> </mx:FormItem> <mx:Button id="submitButton" label="submit" click="submitButton_clickHandler(event)"/> </mx:Form>

components/PaddedPanel.as

// components/PaddedPanel.as package components { import spark.components.Panel; public class PaddedPanel extends Panel { public function PaddedPanel() { // Call the constructor of the superclass. super(); // Set the border styles. setStyle("borderColor", "blue"); setStyle("dropShadowVisible", false); setStyle("cornerRadius", 20); } } }

components/CountryComboBoxSimpleMXML.mxml

<?xml version="1.0" encoding="utf-8"?> <!-- components/CountryComboBoxSimpleMXML.mxml --> <s:ComboBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <s:dataProvider> <s:ArrayList> <fx:String>United States</fx:String> <fx:String>United Kingdom</fx:String> <!-- Add all other countries... --> </s:ArrayList> </s:dataProvider> </s:ComboBox>

To create the SWC file, ensure that the compc compiler is in your system path (if not, add it to the PATH environment variable under your System settings). From the QuickStartLibrary folder, enter the following command:

compc -source-path+=. -output=bin/QuickStartLibrary.swc -include-classes components.AddressFormAlert components.CountryComboBox components.PaddedPanel

Note: Type the preceding command on a single line. It appears here on multiple lines here for the sake of clarity.

Tip: When you use the compc compiler to create a SWC file, you can include any number of components by using namespaces or a manifest file. This can keep the command line command from becoming long and unwieldly. For more information about using namespaces and manifest files, refer to Using compc, the component compiler.

The source-path option includes the current directory in the source path. This is how compc finds the various classes that are listed in the include-classes option.

The output option specifies the output location of the SWC file. In this case, compc writes the QuickStartLibrary.swc file to a folder named bin.

The include-classes option specifies the classes that you want to include in the SWC file. These are the classes you just defined.

Tip: You can also create SWC files by creating a Flex Library Project in Adobe Flash Builder. For more information, refer to Using Flex Builder 4.

Back to top

Deploying SWC files

You use SWC files when compiling MXML files. You typically specify in the library-path option which SWC files the application uses.

The following example uses the AddressForm component from the QuickStartLibrary.swc that you created in the "Creating SWC Files" section.

Example

<?xml version="1.0" encoding="utf-8"?> <!-- DeployingSWC.mxml --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:custom="components.*" width="400" height="310"> <custom:PaddedPanel title="Creating Libraries"> <custom:AddressFormAlert id="addressForm"/> </custom:PaddedPanel> </s:Application>

To compile this example using the stand-alone Flex compiler, enter the following command, substituting the location of the QuickStartLibrary.swc file on your system. In this example, the library is in the ../QuickStartLibrary/bin directory.

mxmlc -library-path+=.;../QuickStartLibrary/bin Main.mxml

Because all SWC files in the flex_install_dir/libs directory are added to the compiler's library path by default, you could just put the QuickStartLibrary.swc file in that directory and compile an application that uses those classes.

Result

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Tip: You can also add SWC files to your Flash Builder projects. To add your SWC file, select Project > Properties > Flex Build Path. On the Library tab, click the Add SWC button and add the QuickStartLibrary\bin directory to your project. The following image shows the QuickStartLibrary.swc file in the project's library path.

flex_builder_swc
alt text

Back to top

For more information

  • Using compc, the component compiler

Back to top


This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement