JS与FLEX|AS实现互相调用
1.AS代码
<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"width="200"height="200"creationComplete="initApp()"><mx:Script><![CDATA[importmx.controls.Alert;importflash.external.ExternalInterface;Security.allowDomain("*");Security.allowInsecureDomain("*");publicfunctioninitApp():void{//js要调用flex方法,首先在flex中必须注册,将as方法注册为js可调用的方法//第一个是js中调用时用的名称,第二个是as中定义的方法ExternalInterface.addCallback("flexFunctionAlias",asFunc);}publicfunctionasFunc():void{Alert.show("js调用flex成功!");}publicfunctiongetJsFunction():void{ExternalInterface.call("getJsName","姓名");//调用js函数getJsName}]]></mx:Script><mx:Buttonclick="getJsFunction()"label="调用js"/></mx:Application>
2.html代码(index.template.html)
functiongetJsName(name){alert("flex调用js成功:"+name);}functiongetFlexMsg(){Test4.flexFunctionAlias();}
<buttononclick="getFlexMsg()">点击调用flex方法</button>
以下为所有的index.template.html代码
<!--savedfromurl=(0014)about:internet--><htmllang="en"><!--SmartdevelopersalwaysViewSource.ThisapplicationwasbuiltusingAdobeFlex,anopensourceframeworkforbuildingrichInternetapplicationsthatgetdeliveredviatheFlashPlayerortodesktopsviaAdobeAIR.LearnmoreaboutFlexathttp://flex.org//--><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><!--BEGINBrowserHistoryrequiredsection--><linkrel="stylesheet"type="text/css"href="history/history.css"/><!--ENDBrowserHistoryrequiredsection--><title>${title}</title><scriptsrc="AC_OETags.js"language="javascript"></script><!--BEGINBrowserHistoryrequiredsection--><scriptsrc="history/history.js"language="javascript"></script><!--ENDBrowserHistoryrequiredsection--><style>body{margin:0px;overflow:hidden}</style><scriptlanguage="JavaScript"type="text/javascript"><!--//-----------------------------------------------------------------------------//Globals//MajorversionofFlashrequiredvarrequiredMajorVersion=${version_major};//MinorversionofFlashrequiredvarrequiredMinorVersion=${version_minor};//MinorversionofFlashrequiredvarrequiredRevision=${version_revision};//-----------------------------------------------------------------------------//--></script></head><bodyscroll="no"><scriptlanguage="JavaScript"type="text/javascript"><!--//VersioncheckfortheFlashPlayerthathastheabilitytostartPlayerProductInstall(6.0r65)varhasProductInstall=DetectFlashVer(6,0,65);//VersioncheckbaseduponthevaluesdefinedinglobalsvarhasRequestedVersion=DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);if(hasProductInstall&&!hasRequestedVersion){//DONOTMODIFYTHEFOLLOWINGFOURLINES//LocationvisitedafterinstallationiscompleteifinstallationisrequiredvarMMPlayerType=(isIE==true)?"ActiveX":"PlugIn";varMMredirectURL=window.location;document.title=document.title.slice(0,47)+"-FlashPlayerInstallation";varMMdoctitle=document.title;AC_FL_RunContent("src","playerProductInstall","FlashVars","MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"","width","${width}","height","${height}","align","middle","id","${application}","quality","high","bgcolor","${bgcolor}","name","${application}","allowScriptAccess","sameDomain","type","application/x-shockwave-flash","pluginspage","http://www.adobe.com/go/getflashplayer");}elseif(hasRequestedVersion){//ifwe'vedetectedanacceptableversion//embedtheFlashContentSWFwhenalltestsarepassedAC_FL_RunContent("src","${swf}","width","${width}","height","${height}","align","middle","id","${application}","quality","high","bgcolor","${bgcolor}","name","${application}","allowScriptAccess","sameDomain","type","application/x-shockwave-flash","pluginspage","http://www.adobe.com/go/getflashplayer");}else{//flashistoooldorwecan'tdetectthepluginvaralternateContent='AlternateHTMLcontentshouldbeplacedhere.'+'ThiscontentrequirestheAdobeFlashPlayer.'+'<ahref=http://www.adobe.com/go/getflash/>GetFlash</a>';document.write(alternateContent);//insertnon-flashcontent}functiongetJsName(name){alert("flex调用js成功:"+name);}functiongetFlexMsg(){Test4.flexFunctionAlias();}//--></script><noscript><objectclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"id="${application}"width="${width}"height="${height}"codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><paramname="movie"value="${swf}.swf"/><paramname="quality"value="high"/><paramname="bgcolor"value="${bgcolor}"/><paramname="allowScriptAccess"value="always"/><embedsrc="${swf}.swf"quality="high"bgcolor="${bgcolor}"width="${width}"height="${height}"name="${application}"align="middle"play="true"loop="false"quality="high"allowScriptAccess="sameDomain"type="application/x-shockwave-flash"pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object></noscript><buttononclick="getFlexMsg()">点击调用flex方法</button></body></html>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。