|
|
flex与activeX不能进行直接通信,一般可以借助js实现.
新建一个flex project
mxml文件代码如下
<?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 flash.external.ExternalInterface;protected function button1_clickHandler(event:MouseEvent):void{if (ExternalInterface.available){ExternalInterface.call("flexcalljs", "Flex call javascript");}}]]--></fx:Script><fx:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --></fx:Declarations><s:Button x="0" y="71" label="Call JS" click="button1_clickHandler(event)"/></s:Application>
载入vc中js与activeX互调项目
修改index.template.html文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><mce:script type="text/javascript" src="history/history.js" mce_src="history/history.js"></mce:script> <mce:script type="text/javascript" src="swfobject.js" mce_src="swfobject.js"></mce:script> <mce:script type="text/javascript"><!-- var swfVersionStr = "10.0.0"; var xiSwfUrlStr = "playerProductInstall.swf"; var flashvars = {}; var params = {}; params.quality = "high"; params.bgcolor = "#ffffff"; params.allowscriptaccess = "sameDomain"; params.allowfullscreen = "true"; var attributes = {}; attributes.id = "flex2js2activex"; attributes.name = "flex2js2activex"; attributes.align = "middle"; swfobject.embedSWF( "flex2js2activex.swf", "flashContent", //要载入的mxml编译后文件以及位置 "400", "200", //在html中的大小 swfVersionStr, xiSwfUrlStr, flashvars, params, attributes); // --></mce:script> </head> <body> <div id="flashContent"></div> //以下脚本也可通过外部js文件导入 <mce:script language="javascript"><!-- //将被Flex调用的JS函数 function flexcalljs(params) { alert("flex call js"); var str = "ActiveX 调用了 JS!(参数是:" + params + ")"; //alert(str); //Flex将通过JS调用ActiveX activexobj = document.getElementById("activex"); activexobj.JS_Call_ActiveX(str); } //将被ActiveX调用的JS函数 function activexcalljs(params) { var str = "ActiveX 调用了 JS!(参数是:" + params + ")"; alert(str); } //将调用ActiveX的函数 function jscallactivex() { str = document.getElementById("inputid").value; activexobj = document.getElementById("activex"); activexobj.JS_Call_ActiveX(str); } // --></mce:script> <object classid="CLSID:37316EB3-933B-45F2-8940-7D8D3039D4E4" id="activex" width="600" height="150"></object> </body></html> |
|