Talk:Fb:fbjs bridge

From Facebook Developer Wiki

Jump to: navigation, search

Contents

[edit] Sending Multiple Parameters

When i send multiple parameters, it puts them all together and passes them to the first parameters. How can I go aroundt his

[edit] Profile Tab IE6 and IE7 Bug

If you have Javascript errors when trying to get the JS => Flash connection to work in a Profile Tab with IE6 and IE7, please vote on bug #5799

--534241990 11:51, 26 June 2009 (PDT)

[edit] Trouble Shooting 1/22/2009

My AS2 to JS wasn't working, turned out: <fb:fbjs_bridge/> MUST BE BEFORE the swf's fb tag. When <fb:fbjs_bridge/> is after the swf, it doesn't work (even though AS2 is returning true for "myConnection.connect(connectionName);" and "myConnection.send(...)"

[edit] This Appears to be Completely Broken 11/23/2008

I am simply trying to get an onclick event from a normal HTML link, to fire and event in flash that will execute a function. Why is this so hard?

Oddly, the following works "occasionally" in IE7; but never in Firefox! Any help would be greatly appreciated.

Within PHP Script:

<fb:fbjs_bridge/> 
<div id="swfContainer"></div> 
<script> 
var swf = document.createElement('fb:swf'); 
swf.setId('my_swf_id'); 
swf.setWidth('520'); 
swf.setHeight('394'); 
swf.setSWFSrc('http://www.myfacebookappsite.com/folder/myswf.swf'); 
document.getElementById('swfContainer').appendChild(swf); 
swf.callSWF('asMethod', 'one', 'two'); 
</script>
<a onclick="document.getElementById('my_swf_id').callSWF('asMethod','arg1','arg2'); return false;" href="#" >Execute ActionScript Function</a>			 

Inside FLASH (AS3):

var connection:LocalConnection=new LocalConnection();
var connectionName:String=LoaderInfo(this.root.loaderInfo).parameters.fb_fbjs_connection;
connection.allowDomain("*");
connection.client = {
   asMethod: function(paramOne:String, paramTwo:String) {
      myCustomSwfFunction();
   }
};
connection.connect(connectionName);



Is this working for anybody as of 9/5/08? I've set up my fbml and as3 just like the examples except I get no behavior at all.

-- I was able to get the AS3 example with the callFBJS implementation working. The non-FBJS example, where it attempts to call navigateToURL through the bridge, doesn't work at all.

[edit] i can't get this to work either!

i have copied this code from the example exactly (with obvious changes to the url):

fmbl:

<fb:fbjs_bridge/>

<script> var swf = document.createElement('fb:swf'); swf.setId('my_swf_id'); swf.setWidth('100'); swf.setHeight('100'); swf.setSWFSrc('FULL_URL_TO_MY_SWF'); document.getElementById('swfContainer').appendChild(swf); swf.callSWF('asMethod', 'one', 'two'); </script>

AS3:

var connection:LocalConnection = new LocalConnection(); var connectionName:String = LoaderInfo(this.root.loaderInfo).parameters.fb_fbjs_connection;

connection.allowDomain("apps.facebook.com", "apps.*.facebook.com"); connection.client = {

   asMethod: function(paramOne:String, paramTwo:String) {
       // do something in the SWF
   }

}; connection.connect(connectionName);


my flash movie will execute the code i put within the asMethod function but the parameters from the swf.callSWF are not getting through. i am trying to build a connect four app in facebook from a game i have developed in flash and it's proving to be almost impossible. i understand the basic concept of the fbjs-bridge and i know communication between flash and fbjs is obviously possible as there are so many great facebook apps that rely heavily on flash but i just cant seem to get it to work! i have posted requests for info about this issue in the forum but have not had any replies and the there is next to nothing out there on the web on the subject. i would just about consider myself an intermediate developer so i guess this is really about a lack of knowledge on my part but i really think there needs to be better documentation and examples (at least examples that work!) as i have wasted hours just trying to get a simple parameter into flash.


[edit] TRY USING THIS EXAMPLE FOR callSWF

[edit] FBML

<fb:fbjs_bridge/>
<script>
var swf = document.createElement('fb:swf');
swf.setId('my_swf_id');
swf.setWidth('200');
swf.setHeight('200');
swf.setSWFSrc('FULL_URL_TO_MY_SWF');
document.getElementById('swfContainer').appendChild(swf);
</script>
<a onclick="document.getElementById('my_swf_id').callSWF('changeText', 'NEW', 'TEXT'); return false;" href="#">Change Text to 'NEW TEXT'</a>


[edit] AS3

import flash.accessibility.*;
import flash.debugger.*;
import flash.display.*;
import flash.errors.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.media.*;
import flash.net.*;
import flash.profiler.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;
import flash.xml.*;
import mx.binding.*
import mx.controls.*;
import mx.core.*;
import mx.events.*;
import mx.styles.*;
var connection:LocalConnection = new LocalConnection(); 
var connectionName:String = LoaderInfo(this.root.loaderInfo).parameters.fb_fbjs_connection; 
connection.allowDomain("*"); 
connection.client = new Object();
connection.client.changeText = function(arg1:*, arg2:*):* { 
    root.test_var.text = arg1 + arg2;
    return
} 
connection.connect(connectionName);
root.test_var.text = connectionName;


[edit] fb_local_connection set wrong

when instantiating the flash with javascript, I find &fb_local_connection=& in flashvars, thus passing in a null value for that parameter. Thus the flash is unable to use the bridge to call javascript. Other flash objects instantiated in the same page with <fb:swf > receive the correct value for this parameter.

[edit] bridge without the tag

After the bridge tag was removed from an app by another developer, the bridge continued to work more often than not, so it appeared that the bridge was still in place, but operating very unreliably.

[edit] AS2 FLash 9 LocalConnection problem.

HI! I'm trying to connect from one SWF to another. But I cant make it work. The onStatus tells me that it works, but i cant call any function on the reciver swf.


// This is the send code: var connection_snd:LocalConnection = new LocalConnection(); var connectionName:String = _root.fb_local_connection; tx_show.text = fb_local_connection; connection_snd.allowDomain("apps.facebook.com","apps.*.facebook.com"); connection_snd.onStatus = function(infoObject:Object) { switch (infoObject.level) { case "status" : tx_show.text += "LocalConnection connected successfully."; break; case "error" : tx_show.text += "LocalConnection encountered an error."; break; } }; function callFBJS(methodName:String, parameters:Array):Void { if (connectionName) { connection_snd.send(connectionName,"callFBJS",methodName,parameters); } } mc_bt.onPress = function() { callFBJS("updateTextField",["Hello World!"]); };

// This is the recive: var connection_rcv:LocalConnection = new LocalConnection(); var connectionName:String = _root.fb_local_connection; tx_show.text = fb_local_connection; connection_rcv.allowDomain("apps.facebook.com","apps.*.facebook.com"); connection_rcv.updateTextField = function(textValue:Array):Void { tx_show.text = textValue; }; connection_rcv.connect(connectionName);

Thanks!

Hi Nicolas, you might get a faster response if you post this on the Developer Forum. Or if you think it's a bug, then you can file it in Bugzilla. Thanks, Pete (563683308 14:39, 20 August 2009 (PDT))

[edit] beware https://

If the flash is referenced with an https:// URL the bridge won't work with it.

reference