javascript与flash函数相互交互

来源:互联网 发布:职场女英文名知乎 编辑:程序博客网 时间:2024/05/07 07:46

Java代码

  1. import flash.external.ExternalInterface;  
  2. function hello(){  
  3. return "测试成功了哦~~";  
  4.     }  
  5. //允许flash调用js函数 参数1:js函数名称 参数2:向js函数传递的参数
  6. ExternalInterface.call("hello", "jacky");  
  7. //允许js调用flash中的函数 参数1:要调用flash函数的js函数,参数2:被调用flash函数
  8. ExternalInterface.addCallback("helloas",hello); 
import flash.external.ExternalInterface;function hello(){return "测试成功了哦~~";}//允许flash调用js函数 参数1:js函数名称 参数2:向js函数传递的参数ExternalInterface.call("hello", "jacky");//允许js调用flash中的函数 参数1:要调用flash函数的js函数,参数2:被调用flash函数ExternalInterface.addCallback("helloas",hello);

接下来是 JSP页面
把你生成SWF 文件放入工程相应的目录下  把路径自己的路径就可以了
当然

Java代码

  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
  2. <%  
  3.     String path = request.getContextPath();  
  4.     String basePath = request.getScheme() + "://"
  5.             + request.getServerName() + ":" + request.getServerPort()  
  6.             + path + "/";  
  7. %>  
  8.   
  9.   
  10.       
  11.     测试  
  12.       
  13.       
  14.       
  15.        
  16.                     
  17.                     
  18.                     
  19.                     
  20.                     
  21.                  
  22.                   pluginspage="http://www.macromedia.com/go/getflashplayer"
  23.                   type="application/x-shockwave-flash" width="560" height="270" allowScriptAccess="always" wmode="transparent" >  
  24.        
  25.   
  26.        
  27.       
  28.