Hi people!
After get one night asleep, reading everything, I could setup the app and access Flash from Javascript using Opensocial. It works at the same domain and crossdomain too.
There're some tricks, hope it helps.
Somes errors that I've faced, all related to security issues. On the same domain, everything was working fine.
Uncaught Error: Error in Actionscript. Use a try/catch block to find error.
function getTextFromJavascript is not available
Error calling method on NPObject
Tools:
Using Flash Professional, version 8.0
Opensocial 0.7 apis
Test.fla
import flash.external.*;
import flash.system.Security;
// trick number 1
System.security.allowDomain('*');
// declaration trick number 2
var methodName:String = "sendTextToFlash";
var instance:Object = null;
var method:Function = getTextFromJavaScript;
//must return true and true
var isAvailable:Boolean = ExternalInterface.available;
var ret:Boolean = ExternalInterface.addCallback(methodName, instance, method);
function getTextFromJavaScript(valor):Void {
teste.text = "From JavaScript: "+valor;
}
test.html (tricks: allowScriptAccess=always and function thisMovie)
<html>
<head>
<script>
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
}else{
if(document[movieName].length != undefined){
return document[movieName][1];
}
return document[movieName];
}
}
function change()
{
thisMovie("abc123").sendTextToFlash("Xddd");
}
</script>
</head>
<body>
SWF OUTSIDE DOMAIN
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="
http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="abc123" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="
http://www.path.com.br/orkut/flash/teste.swf" />