Adobe
产品
Acrobat
Creative Cloud
创意套装
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
更多产品
解决方案
数字营销
数字媒体
教育
金融服务业
政府部门
网页体验管理
更多解决方案
学习帮助下载公司
商店
在线商店
批量许可
查找经销商
搜索
 
信息 登录
欢迎,我的支持
我的帐户
注销
为何登录?登录后可以管理您的帐户,访问试用版下载、产品扩展和社区区域等。
Adobe
产品 分类 购买   搜索  
解決方案 公司
学习
登录 注销 我的货物 我的支持
Date Date
Qty:
Subtotal
Checkout
Adobe 开发者中心 / Flex 开发人员中心 / Flex 快速入门 /

Packaging components

by Adobe

Adobe logo

Created

22 March 2010

页面工具

在 Facebook 上共享
在 Twitter 上共享
在 LinkedIn 上共享
书签
打印

Tags

要求

用户级别

全部

必需产品

  • 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

缺少 Flash player 您必须装有 Flash 10? 您必须装有 Flash 10?

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.

产品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • 移动应用程序
  • Photoshop
  • Touch Apps

解决方案

  • 数字营销
  • 数字媒体
  • 网页体验管理

行业

  • 教育
  • 金融服务业
  • 政府部门

帮助

  • 产品帮助中心
  • 订货和退货
  • 下载和安装
  • 我的 Adobe

学习

  • Adobe 开发人员连接
  • Adobe TV
  • 培训和认证
  • 论坛
  • 设计中心

购买方式

  • 在线商店
  • 批量许可
  • 查找经销商

下载

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

公司

  • 新闻编辑室
  • 合作伙伴计划
  • 公司社会责任
  • 工作机会
  • 投资者关系
  • 事件
  • 法律
  • 安全
  • 联系 Adobe
选择您的地区 中国(更改)
选择您的地区 关闭

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.

使用条款 | 隐私政策和 Cookies (更新)

京 ICP 备 10217899 号 京公网安备 110105010404