Adobe AIR

[转]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.

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

Parsley AIR发布问题解决方法

之前在项目中使用Parsley做为框架,在把依赖的swc用RSL进行发布AIR的情况下,会Inject不了,
后来发现是AIR在IDE里面进行release发布的时候应该是没有把相关的metadata实现编译进去,于是就查了一下,发现不使用IDE的重新编译,使用命令行手工打包可以解决这个问题,
命令行如下:

adt -package -storetype pkcs12 -keystore certificat e.p12 -storepass 123456 TestAirMetadata.air bin-debug/TestAirMetadata-app.xml -C bin-debug .

Flex User Group文档–AIR介绍

一个很有用的PPT,用于向不了解这技术的人介绍
点击下载

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>

FlexBuilder中使用代码片断工具

1.1 工具介绍

使用代码片断工具,您可以存储内容(文档中重复出现的代码如public function …( ):void{   }等)以便快速重复使用。多种软件都含有此工具(例如Dreamweaver),flexbuilder中此工具包含在CFEclipse插件中。

1.2 安装与使用

安装步骤:

a.  帮助       安装新软件;

b.  使用(W)一栏中输入地址   http://www.cfeclipse.org/update

c.  输入网址后按Enter,程序连接服务器,窗口显示“暂挂中”,连接完毕后窗口会显示出可供安装的程序,选择CFEclipse CFML Editor   点 下一步

d.  点 完成  开始下载   出现安全警告提示软件未签名 点击确定  之后按提示重启flex builder

e.  打开工具窗口(Snip Tree View);

f.   编辑代码片断   新建片断

g.  按钮插入该片断(只适用于AS代码文件)

h.  片断中适用参量:$${    }   如图中代码

在插入该片断时会出现提示框,要求输入$${}标记的参数值name  如图

确定后整段代码被插入

Air/Flex动态加载module及其依赖的RSL

有关Flex和Air中如何使用RSL网上教程很多,google一下即可,这里不多做叙述了

而这次遇到的问题是这样的:

发布时只发布一个主程序(Web或者Air方式),而不发布所需要的module及其依赖的swc,只在运行时根据需要加载module及其依赖的swc

1.       建立一个实验用的module工程:

先准备一个module工程,普通的Flex Project(web)即可,主程序名无所谓,因为这个工程只是为了编译module对象用的

在Properties->Flex Build Path中引入所要依赖的swc,这个例子中使用了TweenLite.swc

注意AIR project的默认Link TypeMerge into code,改成RSL。如图:

新建一个包modules并新建一个module程序:MyModule1.mxml

到Properties->Flex Modules中修改该module的optimize属性为none,如下图

点击Edit按钮,弹出下图

选择Do not optimize(…)

在MyModule1.xml中使用TweenLite做一个简单的动画:

TweenLite.to(<strong>this</strong>.goed,4,{x:500});

编译工程,

此时MyModule1.mxml被编译生成为MyModule1.swf

TweenLite.swc会被编译成TweenLite.swf

复制到要被加载的目录下,我的是

http://127.0.0.1/testflex/TweenLite.swf

http://127.0.0.1/testflex/modules/MyModule1.swf

2.       建立主工程(Flex Web):

新建一个Flex Project(web),不要使用引入TweenLite.swc

新建一个用来控制加载TweenLite的类:

tasks/TaskLoadRSL.as

在这个类中,使用URLLoader将TweenLite.swc从http://127.0.0.1/testflex/TweenLite.swf上加载下来,主要代码如下:

var loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;//必须有这一句,RSL必须和主程序在同一个域中
loader.load(new URLRequest(this.web),context);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,localLoadCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,localLoadIoErrorHandler);

加载完TweenLite后不需要任何操作,直接开始加载module即可

使用IModuleInfo或ModuleLoader加载module都可以,详见源代码

3.       建立主工程 (AIR):

Air中比Flex要麻烦,因为发布时只发布主程序,所以运行时需要先检测本地是否有swc和

module

如果有就直接加载运行(同Web)

如果没有就从网站上下载到本地,然后再加载

主要代码如下:

从网络地址上加载:

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, loadFromWebCompleteHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, loadFromWebErrorHandler);
loader.load(new URLRequest(web))

加载完,保存到本地:

var loader:URLLoader = URLLoader($e.target);
var data:ByteArray = ByteArray(loader.data);
var file:File = new File(File.applicationDirectory.resolvePath(this.local).nativePath);
trace('save file to' + file.nativePath);
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(data);
fileStream.close();
this.loadFromLocalFile();

本地加载过程同Flex Web

更多内容参加源代码:DynamicTestLoadModuleAndRSL

httpservice request传参数的几种方式

mxml代码中 httpservice 组件,连接一php计算器

<s:Button click="this.hs.send();"/>
<fx:Declarations>
	<s:HTTPService id="hs" url="http://127.0.0.1/cal.php" method="GET">
		<s:request xmlns="">
			<calculator>plus</calculator>
			<param1>10</param1>
			<param2>23</param2>
		</s:request>
		<s:fault>
			<![CDATA[
				trace("")
			]]>
		</s:fault>
		<s:result>
			<![CDATA[
				trace(event.result.result.equals)
			]]>
		</s:result>
	</s:HTTPService>
</fx:Declarations>

httpService组件,在as块中传入参数

var param:Object = {calculator:"minus",param1:"23",param2:"13"}
httpServ.send(param)

<mx:HTTPService id="httpServ">
	<mx:resultFormat>text</mx:resultFormat>
	<mx:url>http://127.0.0.1/cal.php</mx:url>
	<mx:fault>Alert.show(event.toString(), event.type);</mx:fault>
</mx:HTTPService>

as代码中,使用httpservice类

public var httpservice:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
public var param:Object={calculator:"minus",param1:"23",param2:"13"};
public function send_data():void{
	httpservice.url ="http://127.0.0.1/cal.php";
	httpservice.method = "POST";
	httpservice.addEventListener(ResultEvent.RESULT, resultHandler);
	httpservice.addEventListener(FaultEvent.FAULT, this.HttpErrorHandle);
	httpservice.send(param);
		}

as代码中使用urlloader

public function Temp()
		{
			var url:String = "http://127.0.0.1/cal.php"
			var urlVariables:URLVariables = new URLVariables();
			urlVariables.decode("calculator=plus&param1=10&param2=22");
			var request:URLRequest = new URLRequest(url);
			request.data = urlVariables;
			request.method = URLRequestMethod.POST

			var loader:URLLoader = new URLLoader()
			loader.dataFormat = URLLoaderDataFormat.TEXT
			loader.addEventListener(Event.COMPLETE, onComplete)
			loader.load(request);

		}
		public function onlistener(event:Event):void{
			var xml:XML = new XML(event.target.data)

			trace(xml..equals)
		}