Here is some source code packaged in a zip file that completes the roundtrip for a request from Flex to Javascript for data from an Open Social API.
The code works like this:
1) the gadget.xml defines the plugin code and includes the necessary javascript files.
2) One of the included javascript files is gadget.js, which defines an onload handler that instantiates the flex app and provides a getFlexApp method for obtaining a reference to the Flex application when it is time to call functions on it.
3) In OpenSocial.mxml, the flex app instantiates the FABridge, registers “setFriends” as a function callable by Javascript in the init() function, and provides a handler for a button that will call “getFriends” in the Javascript using the ExternalInterface.
4) The “getFriends” javascript function is defined in bridge.js, which is a file that contains all of the functions that I want the Flex app to use and all the functions that will communicate back to Flex.
5) The function “getFriends” in bridge.js calls the function “loadFriends” found in api.js, which is a file that contains all of the Open Social API specific code, including request handlers that will receive data back from the Open Social container.
6) When the “loadFriends” function in api.js is complete and is ready to return the requested friends data, it will call “setFriends” in the bridge.js file to have the data returned to Flex.
7) Instead of returning the raw data from the OpenSocial APIs, the “loadFriends” function in api.js will use the “addFriends” function in aggregate.js which in turn uses the “makeFriendObject” function in objectify.js to add translate the raw friends data into an array of simple objects for use in Flex. This is what is passed to “setFriends” in the bridge.js file for delivery to Flex.
Questions?
Filed under: Uncategorized