Adobe Flex

Adobe Flex

[转]FlashBuilder中使用fl组件

意思就是:用Flash CS创建一个flash,将需要的fl组件拖进舞台,然后导出swc文件

在FlashBuilder中引入该swc,这时就能在代码中直接new这个fl组件了

How to Use Flash CS’s Components in Flex Builder

To generate the .swc file in Flash CS3, we follow these steps:

1) Make a new Flash CS3 ActionScript 3.0 .fla file.
2) Drag the desired component(s) to the Library. In this example, we’ll drag the TextArea component to the Library.
3) Choose File > Export > Export Movie.
4) For File name, enter v3components.swf. (We don’t even want the generated .swf, but there’s no other way to get the .swc to compile.)
5) Select a folder in which to save the .swf file.
6) Click Save.
7) In the Export Flash Player dialog, check Export SWC.
8) Click OK.

The preceding steps generate two files, cs3 components.swf and v3components.swc, both of which are placed in the folder selected in Step 5.

Now let’s use cs3 components.swc in a Flex Builder project. Follow these steps:

1) In Flex Builder, select File > New > ActionScript Project.
2) For Project name, enter “V3Test.as”.
3) Click Next.
4) For Main source folder, enter “src”.
5) For Main application file, enter “V3Test.as”.
6) On the Library path tab, click Add SWC.
7) Browse to the v3components.swc file from the preceding procedure.
8) Click Finish.
9) Update the code in cs Test.as so it looks like this:

package {
  import flash.display.Sprite;
  import fl.controls.TextArea;
  public class V3Test extends Sprite {
    public function V3Test() {
      var t:TextArea = new TextArea();
      t.text = "You're not cookin'";
      addChild(t);
    }
  }

}
10) Run the project.

AS3在本地选择图片并预览(仅限FlashPlayer10+)

(仅限FlashPlayer10+)

<?xml version="1.0" encoding="utf-8"?>
<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" minWidth="955" minHeight="600"
			    creationComplete="application1_creationCompleteHandler(event)">

	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
			private var file:FileReference;
			private var loader:Loader;
			protected function button1_clickHandler(event:MouseEvent):void
			{
				file = new FileReference();
				file.addEventListener(Event.SELECT,file_selectHandler);
				file.browse ([new FileFilter("Images(*.jpg;*.jpeg;*.png;*.gif)","*.jpg;*.jpeg;*.png;*.gif")]);
			}

			protected function file_selectHandler(event:Event):void{
				file.removeEventListener(Event.SELECT,file_selectHandler);
				file.addEventListener(Event.COMPLETE,file_completeHandler);
				file.load();
			}

			protected function file_completeHandler(event:Event):void{
				file.removeEventListener(Event.COMPLETE,file_completeHandler);
				loader.loadBytes(file.data);
			}
			protected function loaderCompleteHandler(event:Event):void{
				var $bmd:BitmapData = new BitmapData(loader.width,loader.height,true,0x00FFFFFF);
				$bmd.draw(loader.content);
				this.preview.source = $bmd;
				this.preview.width = 40;
				this.preview.height = 40;
			}

			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				loader = new Loader();
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);
				this.swf.addChild(loader);
			}

		]]>
	</fx:Script>
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<s:Button click="button1_clickHandler(event)" label="Select Image"/>
	<s:HGroup>
		<s:BitmapImage id="preview"/>
		<mx:SWFLoader id="swf"/>
	</s:HGroup>
</s:Application>

使用RSL发布flex项目需要的build.xml要诀详解

遇到了一个ANT编译后不能正常发布使用的问题,于是花了两天(人比较呆)去研究,研究得这么辛苦,当然要把心得写下来,对于ADOBE貌似详细,但语蔫不详的文档作风很是失望!
在此感谢此文作者:http://www.kahunaburger.com/2009/04/08/flash-player-verifyerror-error-1014-with-rsls/
给了我解决问题的思路

要是用flash build 4.1自带的flex 4.1的sdk的flex-config.xml记得更新里面的默认编译FP版本为10.1,否则还是10.0的

build.properties文件

#Flex SDK 路径
FLEX_HOME=G:\\flexsdk
#根目录
APP_ROOT=G:\\riasource\\0.trunk
#ANT 安装目录
ANT_HOME=D:\\tools\\apache-ant-1.8.0
#本地部署目录(wamp/www)
DEPLOY_DIR=E:/wamp/www/ihaveu2

build.xml文件

<?xml version="1.0" encoding="utf-8"?>
<project name="Task Build Main Script" default="build" basedir=".">
	<!-- 加载全局properties -->
	<property file="../build.properties" />
	<!-- 源文件路径 -->
	<property name="SRC_DIR" value="${basedir}/srcs" />
	<!-- assets路径 -->
	<property name="ASSETS_DIR" value="${basedir}/assets" />
	<!-- config路径-->
	<property name="CONFIG_DIR" value="${APP_ROOT}/main/config/locale" />
	<!-- 引入flexTasks.jar -->
	<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
	<taskdef resource="net/sf/antcontrib/antlib.xml">
		<classpath>
			<pathelement location="${ANT_HOME}/lib/ant-contrib-1.0b3" />
		</classpath>
	</taskdef>

	<!-- 优化和生成项目需要用到的RSL -->
	<target name="createRSL">
		<macrodef name="optimize-rsl">
			<attribute name="rsl-dir" />
			<attribute name="swc-dir" />
			<attribute name="swc-name" />
			<sequential>
				<unzip src="@{swc-dir}/@{swc-name}.swc" dest="@{rsl-dir}">
					<patternset>
						<include name="library.swf" />
					</patternset>
				</unzip>
				<java jar="${FLEX_HOME}/lib/optimizer.jar" fork="true" failonerror="true">
					<jvmarg line="-ea -DAS3 -DAVMPLUS -Dflexlib=${FLEX_HOME}/frameworks -Xms32m -Xmx384m -Dsun.io.useCanonCaches=false" />
					<arg line="'@{rsl-dir}/library.swf' --output '@{rsl-dir}/@{swc-name}.swf' --keep-as3-metadata='Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient,RemoteClass' " />
				</java>
				<delete file="@{rsl-dir}/library.swf" />
				<java jar="${FLEX_HOME}/lib/digest.jar" fork="true" failonerror="true">
					<jvmarg line="-ea -DAS3 -DAVMPLUS -Xms32m -Xmx384m -Dsun.io.useCanonCaches=false" />
					<arg line="--digest.rsl-file  @{rsl-dir}/@{swc-name}.swf --digest.swc-path  @{swc-dir}/@{swc-name}.swc" />
				</java>
			</sequential>
		</macrodef>		

		<!--把项目依赖的swc变成我们需要的RSL文件-->
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/library/bins" swc-name="ihaveuLib_magazine" />
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/library/bins" swc-name="ihaveuLib_main" />
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/referenceLibs/bins" swc-name="PureMVC_AS3_MultiCore_1_0_5" />
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/referenceLibs/bins" swc-name="TweenLite" />
	</target>

	<!-- 构建web项目  -->
	<target name="build" depends="createRSL" >
		<exec executable="svnversion" outputproperty="revisionVersion" />
		<copy todir="${DEPLOY_DIR}">
			<fileset dir="${SRC_DIR}/web_runtime">
				<include name="**/**" />
			</fileset>
		</copy>

		<copy todir="${DEPLOY_DIR}/assets">
			<fileset dir="${ASSETS_DIR}/web_runtime">
				<include name="**/**" />
			</fileset>
			<!--
			<fileset dir="${ASSETS_DIR}/air_runtime">
				<include name="**/**" />
			</fileset>
			-->
		</copy>

		<mxmlc file="${DEPLOY_DIR}/index.mxml">
			<!-- 方便可以进行远程debug -->
			<debug>true</debug>
			<!-- 项目需要用到的locale名字,其中在SDK 4.1 里面framework locale目录zh_tw已经改成zh_TW,但千万别信,使用的时候还是要写成zh_tw -->
			<locale>en_US</locale>
			<locale>zh_CN</locale>
			<locale>zh_tw</locale>
			<!--项目的多语言及配置文件目录-->
			<source-path path-element="${CONFIG_DIR}/en_US" />
			<source-path path-element="${CONFIG_DIR}/zh_CN" />
			<source-path path-element="${CONFIG_DIR}/zh_tw" />
			<!-- 依赖的flex 4.1框架的RSL, 注意:顺序不能乱!若不写这一段则会报错:VerifyError: Error #1014: 无法找到类 。估计是由于下面自己定义的RSL依赖次序被优先了 -->
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/framework_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="framework_4.1.0.16076.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/textLayout.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/tlf/1.1.0.604/textLayout_1.1.0.604.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="textLayout_1.1.0.604.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="libs/osmf.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/osmf_flex.4.0.0.13495.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="osmf_flex.4.0.0.13495.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/spark.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/spark_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="spark_4.1.0.16076.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/sparkskins.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/sparkskins_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="sparkskins_4.1.0.16076.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/rpc.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/rpc_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="rpc_4.1.0.16076.swz" />
			</runtime-shared-library-path>
			<!-- 依赖的第三方RSL, 如果有依赖关系,则应该按照依赖次序 进行定义-->
			<runtime-shared-library-path path-element="${APP_ROOT}/referenceLibs/bins/PureMVC_AS3_MultiCore_1_0_5.swc">
				<url rsl-url="PureMVC_AS3_MultiCore_1_0_5.swf" policy-file-url=""/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${APP_ROOT}/referenceLibs/bins/TweenLite.swc">
				<url rsl-url="TweenLite.swf" policy-file-url=""/>
			</runtime-shared-library-path>		

			<runtime-shared-library-path path-element="${APP_ROOT}/library/bins/ihaveuLib_main.swc">
				<url rsl-url="ihaveuLib_main.swf" policy-file-url=""/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${APP_ROOT}/library/bins/ihaveuLib_magazine.swc">
				<url rsl-url="ihaveuLib_magazine.swf" policy-file-url=""/>
			</runtime-shared-library-path>
			<!-- 指定哪些包是不需要编译进输出的swf, 不写这段会把框架打包进index.swf里面去 -->
			<external-library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
				<include name="*.swc" />
				<include name="air/*.swc" />
			</external-library-path>
		</mxmlc>
	</target>
</project>

Flex 4.1以及Flash Builder 4.0.1更新

针对Flash Player 10.1的开发工具更新,快更新吧!

Adobe has publicly pushed the Flex 4.1/Flash Builder 4.0.1 update, which includes:

The new Layout Mirroring feature for repurposing Flex UIs for deployment in right-to-left locales
Native support for Flash Player 10.1 and AIR 2 in the Flex SDK
Native support in Flash Builder 4.0.1 for building apps targeting SDK 4.1, AIR 2 or FP 10.1
Many critical bugfixes and enhancement requests for both Flex SDK and Flash Builder

Adobe has also officially debuted the next release of the Flex SDK, code-named Hero. We share with the world our amazing story of a single unified Flex framework that can be used to build applications for the web, desktop and mobile devices. With today’s debut, we released many new documents and feature specifications, including:

Inaugural launch of the new Hero opensource Flex page
Posting of several new Hero desktop and Hero mobile feature specifications
Updated the labs.adobe.com Flex Mobile content to announce our intent to add mobile development capabilities directly into the core Flex framework, including
o Updating the Flex and Mobile Whitepaper
o Updating the Flex and Mobile FAQ

Please help us spread the word regarding these announcements. You can find more details in the following two blog postings:
Flex SDK 4 and Flash Builder 4 Updates Now Available http://blogs.adobe.com/flex/archives/2010/06/flex_sdk_4_and_flash_builder_4.html
Introducing….Hero!

http://blogs.adobe.com/flex/archives/2010/06/introducinghero.html

Adobe Flash Player 10.1 and Adobe AIR 2 正式发布

Rachel Luxemburg wrote:

Hi All!

Adobe Flash Player 10.1 and Adobe AIR 2 are now available for Windows, Mac and Linux operating systems. To download the runtimes, go to http://get.adobe.com/flashplayer/ for Flash Player and
http://get.adobe.com/air/ for AIR 2.

More info is posted on the AIR team blog, http://blogs.adobe.com/air/ and the Flash Player Team blog http://blogs.adobe.com/flashplayer/.

We’re really excited that we’re finally “over the finish line” with these releases, there’s a lot of new features & some real performance improvements.

Please help spread the word, and enjoy!

Rachel

Flash在IE全屏时 使用Deeplinking修改网址会退出全屏的bug解决方案

BUG描述:

IE浏览器下,Flash全屏时 一旦使用deeplinking修改网址参数,就会导致Flash退出全屏

解决方案:

在全屏时不再修改deeplinking, 而当退出全屏时,使用最后的deeplinking

可以侦听stage类的事件FullScreenEvent. FULL_SCREEN

在任何被添加到了舞台的DisplayObject对象内部,都可以这样写:

this.stage.addEventListener(FullScreenEvent.FULL_SCREEN, stage_fullScreenHandler);

//侦听全屏变化的事件

private function stage_fullScreenHandler(event:FullScreenEvent):void{

//event.fullScreen为false的时候,是退出全屏,true是进入全屏

if(!event.fullScreen){

//修改deeplinking

}

Flex4 SkinnableContainer,BorderContainer隐藏子内容

SkinnableContainer及其子类BorderContainer等在添加了子内容后,

即使子内容宽高超过了容器本身的宽高,子内容也会被正常显示出来,

SkinnableContainer是无法裁剪子内容的,而且也没有默认属性可以设置

但如果想实现容器裁剪子内容,可以用以下方法实现

<s: SkinnableContainer id=”myBC” creationComplete=”myBC.contentGroup.clipAndEnableScrolling = true”>

即:在容器创建完成后设置它的属性contentGroup的clipAndEnableScrolling为true

原理:

BorderContainer继承自SkinnableContainer,这两个组件都不是自身添加显示对象的,而是使用contentGroup作为子内容的容器,

而contentGroup实际上是一个Group对象 Group本身有一个属性:clipAndEnableScrolling,当它为true时,就会裁剪内容,默认是false

FlashFlex发布可访问本地的SWF

无论是Flex还是Flash编译后的SWF都只可方位网络或者只可访问本地数据,不可以同时访问二者,
Flex默认是只可访问网络,要把Flex编译后的SWF设为只可访问本地数据模式,要在Flex项目的编译参数中增加:-use-network=false
在Flash IDE中,设置方式:在菜单工具栏中选择File(文件)->Publish Settings(发布设置),在弹出窗口中选择Flash标签,在Local playback中选择需要的访问模式

Flex4动态加载和切换CSS

Flex4中动态加载CSS文件的方式已经和Flex3有了一定的区别

主要步骤如下:

1.编写不同的CSS文件

见后文

2.将CSS文件编译成SWF文件

在FlashBuilder中右键CSS文件,选择Compile CSS to SWF,
Read More »

Flex中的Base64加解密

Flex sdk3就内置了Base64的加/解密工具类
分别是
mx.utils.Base64Encoder
mx.utils.Base64Decoder

Base64Encoder用法如下:
var $orgin:String = this.textOrigi.text;//获取原始字符串
var $base64:Base64Encoder = new Base64Encoder();
$base64.insertNewLines = false;//该值等于true时,输出的结果会自动换行,默认为true,
$base64.encodeUTFBytes($orgin);//这里注意,如果想加密中文就不要使用$base64.encode();
var $result:String = $base64.toString();//输出结果
Base64Decoder用法如下:
				var $origi:String = this.textEncodeResult.text;//获取原始字符串
				var $base64:Base64Decoder = new Base64Decoder();
				$base64.decode($origi);
				var $result:String = $base64.toByteArray().toString();//输出结果,decode类只能输出ByteArray类型的数据,因此要转换成string
完成代码:
<?xml version="1.0" encoding="utf-8"?>
<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" minWidth="955" minHeight="600">

	<fx:Script>
		<![CDATA[
			import mx.utils.Base64Decoder;
			import mx.utils.Base64Encoder;
			protected function btnEncode_clickHandler(event:MouseEvent):void
			{
				var $orgin:String = this.textOrigi.text;//获取原始字符串
				var $base64:Base64Encoder = new Base64Encoder();
				$base64.insertNewLines = false;//该值等于true时,输出的结果会自动换行,默认为true,
				$base64.encodeUTFBytes($orgin);//这里注意,如果想加密中文就不要使用$base64.encode();
				var $result:String = $base64.toString();//输出结果
				this.textEncodeResult.text = $result
			}

			protected function btnDecode_clickHandler(event:MouseEvent):void
			{
				var $origi:String = this.textEncodeResult.text;//获取原始字符串
				var $base64:Base64Decoder = new Base64Decoder();
				$base64.decode($origi);
				var $result:String = $base64.toByteArray().toString();//输出结果,decode类只能输出ByteArray类型的数据,因此要转换成string
				this.textDecodeResult.text = $result
			}

		]]>
	</fx:Script>

	<mx:Form width="100%">
		<mx:FormItem label="原始字符串:" width="100%">
			<s:TextArea editable="true" id="textOrigi" width="100%" text="在这里输入原始字符串"/>
		</mx:FormItem>
		<mx:FormItem>
			<s:Button id="btnEncode" label="Encode Base64" enabled="{this.textOrigi.text!=''}" click="btnEncode_clickHandler(event)"/>
		</mx:FormItem>
		<mx:FormItem label="Encode 结果:" width="100%">
			<s:TextArea editable="false" id="textEncodeResult" width="100%"/>
		</mx:FormItem>
		<mx:FormItem>
			<s:Button id="btnDecode" enabled="{this.textEncodeResult.text!=''}" label="Decode Base64" click="btnDecode_clickHandler(event)"/>
		</mx:FormItem>
		<mx:FormItem label="Decode 结果:" width="100%">
			<s:TextArea editable="false" id="textDecodeResult" width="100%" text="点击Decode Base64按钮后,这里的结果应该和原始字符串相同"/>
		</mx:FormItem>
	</mx:Form>
</s:Application>