flex调用as2的swf
由于avm版本的问题,flex3无法直接调用flash做的swf文件,弄了一天,最后终于想到了一个办法,将LocalConnect和flex调用as3两种方式攒在了一起,算是暂时把这个问题解决了!
存起来,留着以后修改
第一步:用flash做一个as2的文件
我在里面添加了一个按钮
在第一帧写下面的代码
mybtn.onRelease=function()
{
var caller:LocalConnection=new LocalConnection();
caller.send("as_server","testAs3",this._name);//this._name为第二步中创建的swf里testAs3的参数
}
第二步:创建一个flash做的as3的文件,包含一个名为lab的label
添加下面的代码
var server:LocalConnection = new LocalConnection();
server.connect("as_server");
server.client = this;
function testAs3(msg:String):void{
lab.text=msg;
app.appshowtext(lab.text);
}
var app:Object;
function swfshowtext(str:String):void{
lab.text=str;
}
function setApp(ap:Object):void{
this.app=ap;
}
function testAs31(msg:String,str:String):void{
lab.text=msg+str;
app.appshowtext(lab.text);
}
第三步:写flex代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
private function onSwfLoaded(event:Event):void{
Object(myloader.content).setApp(this);
}
//准备给swf调用的方法
public function appshowtext(str:String):void{
textinput.text=str;
}
]]>
</mx:Script>
<mx:SWFLoader id="myloade" source="../daohang.swf" autoLoad="true" scaleContent="false"/>
<mx:TextInput id="textinput"/>
<mx:SWFLoader id="myloader" source="../demo1.swf" creationComplete="onSwfLoaded(event)" autoLoad="true" scaleContent="false" width="370" height="168"/>
<mx:Button label="send to local.swf" click="Object(myloader.content).swfshowtext(textinput.text);"/>
</mx:Application>
运行一下,ok!!!
相关文档:
测试文件代码如下:导入com.hillelcoren.components包
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:hc="com.hillelcoren.components.*"
xmlns:classes="com.hillelcoren.components.autoComplete.classes.*"
xmlns:l ......
1、当创建一个数组的时候避免用new操作符,用 var a:Array = [];而不用var a:Array = new Array();
2、快速的复制一个数组:
var copy : Array = sourceArray.concat ();
3、设置一个数组的值是非常忙的:
employees.push ( employee ); employees[2] = employee;
4、从一个数组中取得值的速度是设置一个数组值的两倍 ......
1、假如一个自定义控件被用在一个主控件里,在自定义控件里的方法可以转换为主控件的方法,完成调用。
userRulesCanvas.mxml 和 editRulesCanvas.mxml
compent控件代码如下:
private function submitClick():void
{
......
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Alert control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script& ......
XML 作为数据源的实例(TESTED)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" preinitialize="preInit()" fontSize="12" height="500">
<mx:Script>
  ......