文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>flex与JavaScript交互

flex与JavaScript交互

时间:2009-08-06  来源:integergx

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">  
  3.     <mx:Script>  
  4.         <![CDATA[ 
  5.             private function init():void{ 
  6.                 if(ExternalInterface.available){ 
  7.                     //将AS方法注册为JS可以调用的方法 
  8.                     ExternalInterface.addCallback("flexMethod", flexMethod); 
  9.                 } 
  10.             } 
  11.               
  12.             public function flexMethod(s:String):void{ 
  13.                 txt1.text = s; 
  14.             } 
  15.              
  16.             private function callJavaScriptMethod():void{ 
  17.                 if(ExternalInterface.available){ 
  18.                     //在AS中调用JS的方法 
  19.                     ExternalInterface.call("jsMethod", "MM"); 
  20.                     //ExternalInterface.call("window.location.reload"); 
  21.                 } 
  22.             } 
  23.         ]]>  
  24.     </mx:Script>  
  25.       
  26.     <mx:Button x="27" y="28" label="Load" click="callJavaScriptMethod()"/>  
  27.     <mx:TextArea x="27" y="58" width="450" height="143" id="txt1"/>  
  28.       
  29. </mx:Application>  

 

二、在/html-template/index.template.html模板文件中添加以下代码:

Html代码 
  1. <script language="javascript">  
  2.     function callFlexMethod(text){  
  3.         //${application}.flexMethod(text);  
  4.         document.getElementById("${application}").flexMethod(text);  
  5.     }  
  6.       
  7.     function jsMethod(text){   
  8.         alert("hello " + text);  
  9.     }  
  10. </script>  
  11.   
  12. <input type=button value="click" onclick="callFlexMethod('ddddd')">  
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载