Flex与Flash交互
FlashCS3代码:
import flash.net.LocalConnection;
var conn:LocalConnection=new LocalConnection();
conn.client=this;
conn.connect("conToFlash");
function setFlash(ti:String,desc:String):void{
tiTitle.text=ti;
taDesc.text=desc;
}
Flex代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" fontSize="12" creationComplete="init()">
<mx:Script>
<![CDATA[
private var con:LocalConnection;
private function init():void{
con=new LocalConnection();
con.addEventListener(StatusEvent.STATUS,onStatus);
}
private function onClick():void{
con.send("conToFlash","setFlash",tiTitle.text,taDesc.text);
}
private function onStatus(event:StatusEvent):void{
switch(event.level){
case "status":
pan.title="LocalConnection.send()succeeded";
break;
case "error":
pan.title="LocalConnection.send() failed";
break;
}
}
]]>
</mx:Script>
<mx:Panel x="87" y="62" id="pan" width="381" height="261" layout="absolute">
<mx:Form x="23" y="21" width="294" height="172">
<mx:FormItem label="标题">
<mx:TextInput id="tiTitle"/>
</mx:FormItem>
<mx:FormItem label="内容">
<mx:TextInput height="65" id="taDesc"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="send to Flash" click="onClick()"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application>