среда, 2 января 2008 г.

Flex and ApEx: exchanging data

Following my post Flex and Oracle, I wanted to investigate how difficult it would be to exchange data between flex and ApEx. After some trial and error I’m pleased to say that it isn’t that hard to exchange data between both technologies.

I started by looking for a way to get a simple string from a flex application to an ApEx application. I came across the ActionScript API "ExternalInterface". The Adobe documentation for the api:


The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container or a desktop application with Flash Player embedded.

ExternalInterface has a method "call" where you can specify the name of the external function you want to call, the second parameters are the parameters you want to pass to that function.



In your html page make a function called "setDept" with the necessary parameters and let the fill the Apex Items. Make a clickhandler in your flex application and call your function, you will see that it works perfect.

Now we have send data from flex to ApEx, it’s time to send something back from ApEx to flex. To start we need to be sure we have a JavaScript function that allows us to speak with the swf file. After some searching, trial and error, I came across the next function that works in both Mozilla and IE:



Now we need to create a javascript function that will pass a String to our flex application using the thisMovie function. Once this is done the only thing we need to create an ActionScript function that can registers an ActionScript method as callable from the container. We can use the method "callBack" from the "ExternalInterface" class for this.
Your Actionscript could look something like this:



Test the JavaScript function on your html page and you will see that you send data from your ApEx application to your flex application.



Комментариев нет: