1. On the Facebook Canvas page insert a <fb:fbjs-bridge/> tag ABOVE your embedded flash movie (very important that it is ABOVE).
2. Insert the <fb:swf /> as indicated in the Facebook docs. Facebook will automatically pass a localConnection name via flashvars into the swf (the var is called "fb_local_connection").
3. In your flash movie get the localConnection name that Facebook passed in:
private var connectionName:String = Application.application.parameters.fb_local_connection;
4. Facebook exposes the Javascript that has been placed on a Canvas page by providing the function "callFBJS" in the bridge flash movie. This function requires two arguments:
callFBJS(myFunctionName:String,myArgs:Array)
5. With this info you can make the connection and call the javascript function:
connection.send(connectionName,"callFBJS",myFunctionName,myArgs);
Here is the sample code of a AS3 Flex app that call a js function on the canvas page called: showInvite();
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="components.*" creationComplete="init();">
<mx:Script>
<![CDATA[
import flash.net.LocalConnection;
private var connection:LocalConnection = new LocalConnection();
private var connectionName:String = "";
private function init():void{
connectionName = Application.application.parameters.fb_local_connection;
}
private function callFBJS(methodName:String,args:Array):void {
if (connectionName!=""){
connection.allowDomain("apps.facebook.com", "apps.*.facebook.com");
connection.send(connectionName,"callFBJS",methodName,args);
}
}
private function showInvite():void{
var args:Array = new Array("arg1","arg2");
callFBJS("showInvite",args);
}
]]>
</mx:Script>
<mx:Button x="40" y="10" label="click" click="showInvite()"/>
</mx:Application>
For more info on this evolving drama (Facebook changes stuff all the time it appears): http://wiki.developers.facebook.com/index.php/Fb:fbjs-bridge
