加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Calling Flex / Actionscript functions from Javascript

发布时间:2020-12-15 03:43:57 所属栏目:百科 来源:网络整理
导读:Nowadays I am working with Flex projects,that runs on Lotus Notes platform,which consumes data from Lotus Notes backend. Since there is no remote services like BlazeDS to connect to Notes server,am now greatly dependant on HTTPService and


Nowadays I am working with Flex projects,that runs on Lotus Notes platform,which consumes data from Lotus Notes backend. Since there is no remote services like BlazeDS to connect to Notes server,am now greatly dependant on HTTPService and Javascript. Calling a javascript function from Flex is quite easy. Just use the?ExternalInterface?API. For those who don’t know the way,this is how it is getting called.

In AS3

if(ExternalInterface.available){
ExternalInterface.call(“openNotes”,parameter);
}

In Javascript

function openNotes(notesUrl){
window.open(notesUrl,”,‘width=1000,height=600′);
}

It is quite easy. But what if you need to call the reverse. ie,calling actionscript function from javascript. We can use the sameExternalInterface?api for achieve this. There is a method calledaddCallback,available in ExternalInterface. addCallback method 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. The first parameter is the name by which the container can invoke the function and the second parameter is the function closure to invoke. Below is the step-by-step configuration:

Step 1?: Register the call back from actionscript. For eg,call the below method in the creationComplete or initialize event of the component.

private function createCallBack(event:Event):void{
ExternalInterface.addCallback(“updateNotes”,getNotes);
}

private function getNotes():void{
//do whatever you want after getting the hold
}

Step 2 : Create logic in javascript to invoke the AS3 function.

//Javascript
function updateFlex(){
appName.updateNotes();
}

The?appName?is the name and id of the embedded swf object in the HTML. Like below :

That’s it. Now you can call the?updateFlex?javascript method from your HTML and it will invoke the AS3 callback function. Enjoy Coding guys. Flex Your Life. Cheers.?:)




Reference:

http://deviltechie.wordpress.com/2012/05/08/calling-flex-actionscript-functions-from-javascript/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读