Calling Flex/Actript functionfrom Javascript

2109 ワード

Nowadays I amwoking with Freef projecs、that runs on on Lotus Notes plotform、which consumes data from Lotus Notes Notes.Sincthee there ise e e e e e services BlazDS to connectto Noteserver ver am、nowfurererereredededededededededededededededededededededededededededededededededeffftttttttttttttfffrerererever ver ver ver ver ver ver ver ver ver ver ver ver ver ver ver ver amamamamamamamamamamamamamamaaaaaaaaa External Interface API.For those who don't know the way,this is how it is getting caled.
In AS 3
if(External Interface.available){External Interface.call(「openNotes」、parameter)}
In Javascript
function openNotes(notes Url){window.open(notes Url)”、‘width=1000、height=600’);
It is quite easury.But what if you need to call the reverse.ie,caling actioncript function from javascript.We can use the sameExternal Interface appi for achieve this.The re is a method caledadd Callback,available in External Interface.addCallback method register s an Actript method cable from the container.Aftera success ful invotion of  addCallBack(),the registed function in the plear can be caled by JavaScript or ActiveX code in the container.The first parameter is the name by which the container can the function and the second parameter the funce.
Step 1 : Register the call back from actioncript.For eg,cal the below method in the creationCompletter initiaze event of the component.
prvate function createCallBack(event:Event):void{External Interface.addCallback(“udateNotes”、get Notes);}
prvate function get Notes():void{/do whatever you want after getting the hold}
Step 2:Create logic in javascript to invoke the AS 3 function.
//Javascript function udateFlex(){appName.udateNotes()}
The appName is the name and id of the embedded swf object in the HTML.Like below:

That’s it.Now you can cal the udateFlex javascript method from your HTML and it will invoke the AS 3 calback function.Enjoy Coding gys.Flex Your Life.Cheers. :)
Reference:
http://deviltechie.wordpress.com/2012/05/08/calling-flex-actionscript-functions-from-javascript/