flex与flash之间的调用例二
flex与flash之间的调用例二
注:这种方法调用的swf不需要在前台页面显示,只是单纯为了调用swf里面的方法或属性的
? 该方法加载swf的过程中不能单纯把生成的swf文件放在flex项目里,还必须要把与swf相关的资源都加载到bin-debug目录下,否则会加载未完成的错。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="12" layout="absolute" borderColor="#280303" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#F4E9E9, #F8F2F2]">
??<mx:Script>
??<![CDATA[
???import mx.core.UIComponent;
???import mx.controls.Alert;
???import flash.display.Loader;
???import flash.events.Event;
???
???
???private var loader:Loader;
???private var tempArry:Array;
???private function submit():void
???{
??? resbt.enabled=true;
??? loader=new Loader();
???????????? loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
???????????? loader.load(new URLRequest(swfurl.text));
???}
???private function showTestResult():void
???{
?????????????? tempArry=optionVal.text.split("|");??
?????????????? Alert.show(tempArry.toString());???
???}
???
???private function loaderHandler(evt:Event):void
???{
????var mc:MovieClip=evt.target.content as MovieClip;? //注意这句的写法???
???// var mc:MovieClip=loader.content as MovieClip;? 也可以这样写?
????var result:String=mc.test("flex传给该flash方法的字符串参数");
??? Alert.show("result"+result);
???}
???
???
??]]>
?</mx:Script>
?
??<mx:Label text="1.要检测的量表系统路径" x="269" y="82"/>
??<mx:TextInput id="swfurl" text="source/" x="295" y="108"/>
??<mx:Label text="2.请录入选项数值" x="269" y="149"/>
??<mx:TextInput id="optionVal" x="295" y="175"/>
??<mx:Button x="269" y="220" label="提交" click="submit();"/>
??<mx:Button id="resbt" label="查看测试结果" click="showTestResult();" x="374" y="220" enabled="false"/>
??<mx:VBox id="resultBox" visible="false" x="279" y="273" width="199" height="191" horizontalAlign="center">
???<mx:Label id="type" fontSize="14" text="此次测验的结果如下:"/>
???<mx:Label id="raw" text="原始总分"/>
???<mx:Label id="nomal" text="标准总分"/>
???<mx:Label id="level" text="等级"/>
??</mx:VBox>
??
??????
</mx:Application>