Flex调用js方法传递参数
来源:互联网 发布:ember.js 视频教程 编辑:程序博客网 时间:2024/05/08 01:53
在上传完文件以后需要将文件信息加载到session中,但是在监听器中没有使用filter拦截,所以决定把文件的关键字传递到jsp页面然后在通过页面调用action。这样上传文件的信息就可以写入session中了。
开始没有接触过这方面内容,从网络上搜索了一下这个功能实现起来还是比较简单的。
首先要在FLex文件中引入import flash.external.ExternalInterface;关于ExternalInterface解释为: The ExternalInterface class is an application programming interface that enables straightforward communication between ActionScript and the SWF container– for example, an HTML page with JavaScript or a desktop application that uses Flash Player to display a SWF file.
Using the ExternalInterface class, you can call an ActionScript function in the Flash runtime, using JavaScript in the HTML page. The ActionScript function can return a value, and JavaScript receives it immediately as the return value of the call.(摘自:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#
然后在as代码中添加如下代码
private function progressBar_complete(evt:Event):void { //向js传信息initApp();//调用写入session消息callJs();} public function myFunc():String {return fileRef.name +"/" + fileRef.size + "/" +fileComment.text + "/" + fileRef.type;}public function initApp():void {ExternalInterface.addCallback("myFlexFunction",myFunc);}public function callJs():void{var flexToJs:String = ExternalInterface.call("callAction","writeSession");}
progressBar_complete是进度条到达100%以后的效果,代码意思就是当进度条到达100%(文件上传完成以后)调用js方法
initApp 是像js传递参数,参数就是myFunc的返回值
addCallBack()方法:
public static function addCallback(functionName:String, closure:Function):void
Registers an ActionScript method as callable from the container. After a successful invocation of addCallBack()
, the registered function in the player can be called by JavaScript or ActiveX code in the container.
addCallback 像js传值
Call方法:
public static function call(functionName:String, ... arguments):*
Calls a function exposed by the SWF container, passing zero or more arguments. If the function is not available, the call returns null
; otherwise it returns the value provided by the function. Recursion is not permitted on Opera or Netscape browsers; on these browsers a recursive call produces a null
response. (Recursion is supported on Internet Explorer and Firefox browsers.)
If the container is an HTML page, this method invokes a JavaScript function in a script
element.
If the container is another ActiveX container, this method dispatches the FlashCall ActiveX event with the specified name, and the container processes the event.
If the container is hosting the Netscape plug-in, you can either write custom support for the new NPRuntime interface or embed an HTML control and embed the player within the HTML control. If you embed an HTML control, you can communicate with the player through a JavaScript interface to the native container application.
var flexToJs:String = ExternalInterface.call("callAction","canshu");
此方法是调用js方法callAction方法,并向其传参数"canshu",得到返回值flexTojs
Flex和Js相互调用有利于传递参数,例如Flex可以传递文件信息给js,js同样可以传递给Flex一些信息
另外还有给文件上传添加背景图片的代码,样式如下:
如何给Flex 添加背景图片将在后面的博客中叙述。
- Flex调用js方法传递参数
- Flex中调用和传递参数
- flex和js进行参数传递
- flex调用js写文件时,传递的参数包含中文,读取乱码问题
- flex 4.6 javascript 调用 flex 并传递参数
- Flex中窗体参数传递方法
- 网页传递参数到flex中的方法
- JS的参数传递方法
- js 方法传递对象参数
- android原生webview中调用JS方法并传递参数给JS遇到的问题
- js调用setTimeout 时传递参数
- JS 将函数作为参数传递调用
- 让JS中settimeout、setInterval调用传递参数 的好方法
- 开发日志:onclick调用js方法传递多个使用struts标签获取的参数
- dwr调用参数为 对象数组 的方法(js中直接传递obj数组)
- JS调用OC简单实例-传递一个或者多个参数给oc方法
- <a>标签中的onclick调用js方法传递多个参数的解决方案
- JS调用Andrioid方法传递参数,Android需要知道的一个注意点
- nyoj-453-小珂的烦恼
- android FrameWork家族是怎么组成的?
- C++ Primer 第二部分 理解和笔记
- printf的用法
- Qt qnamespace.h 中不包含Q_ENUMS(ItemDataRole),使得Qt::ItemDataRole无法在QtScript下使用,这里是一个Workaround。
- Flex调用js方法传递参数
- Microsoft Visual Studio 2010 使用方法
- hdu1760 A New Tetris Game 博弈,Dfs
- POJ2955 Brackets 动态规划
- 囚禁1
- 1068:P,MTHBGWB
- 使用BaseAdapter实现复杂的ListView
- 8.5 注册码
- 汉诺塔问题