PDA

View Full Version : Local connection not working


Bernie
05-29-2007, 12:18 AM
Hi all
I have been trying to set a local connection to control a set of panoramas from an external flash, place in the same html both (panorama and external flash) with SWFobjet both.

The funny thing about it is that the bloody thing doesn't work when they are together in the same page but works when i place the external flash alone in another html or just from the swf itself.

The code for the html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="es" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Adobe GoLive" />
<script type="text/javascript" src="../js/swfobject.js"></script>
<title>Lobby</title>
<style type="text/css" media="screen"><!--
div#panoramica { position: relative; top: 0; left: 0; width: 300px; height: 200px; margin: 0; padding: 0; }
div#spacer_pan { width: 300px; height: 35px; margin: 0; padding: 0; border-bottom: 1px solid #7e7e7e; }
div#thumbs { width: 400px; height: 60px; margin: 10px 0 0; padding: 0; }
--></style>
</head>

<body>
<div id="panoramica">
Se necesita flash player 9 (http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash) para su vizualizaciуn
<script type="text/javascript">
var fo = new FlashObject("lobbie.swf", "Panoramica", "320", "200", "9",null);
fo.addParam("allowScriptAccess","sameDomain");
fo.addVariable("loaderBackColor", "000000");
fo.write("panoramica");
window.document["pano"].focus();
</script>
</div>
<div id="spacer_pan">
</div>
<div id="thumbs">
<script type="text/javascript">
var so = new FlashObject("barra.swf", "Barra", "400", "60", "9",null);
so.addParam("allowScriptAccess","sameDomain");
so.write("thumbs");
</script>
</div>
</body>

</html>

the code for the external flash (barra.swf in the html code):
// Use the same name in spots.xml: <global controller="lc_test">
// Better use different controller names for different panorama applications
var controllerName = "lc_test";
// Master slot name:
var masterSlot:String;
// Slave slot name:
var slaveSlot:String;
// Begin of connection code (better use it as is).
var dumpSlot = controllerName+"_dump_"+random(1000000);
var _lc = new LocalConnection();
_lc.allowDomain = function() {
return true;
// allow all connections
};
_lc.connect(dumpSlot);
_lc.onStatus = function(info) {
if (info.level == "error") {
trace("No master connection detected.");
_lc.close();
delete _lc;
}
};
_lc.setSlot = function(slot) {
masterSlot = controllerName+"_master_"+slot;
slaveSlot = controllerName+"_slave_"+slot+"_"+random(1000000);
_lc.close();
_lc.connect(slaveSlot);
trace("set slave: "+slaveSlot);
startWatch();
};
_lc.send(controllerName+"_master_0", "getSlot", dumpSlot);
// end of connecion code
var panoName:String;
// current pano name
var panoBusy:Boolean;
// true if panorama is loading or a transition effect is in process
var iid:Number;
// interval id
// start watching parameters "panoName" and "panoBusy":
function startWatch() {
iid = setInterval(this, "sendQuery", 500);
}
// send query:
function sendQuery() {
// 3rd argument is array of askable parameters, 4th and 5th are connection name to callback
_lc.send(masterSlot, "getParams", ["pano.panoName", "pano2.panoName"], slaveSlot, "callback");
}
// listener function:
_lc.callback = function(values) {
// store panoName
panoName = values[1] != null ? values[1] : values[0];
// if the second panorama is not null, set busy flag:
panoBusy = values[1] != null;
};
// remove focus manager, let the panorama has the focus
focusManager.enabled = false;
focusManager = null;
///
var myArray:Array = Array();
myArray[1] = "pano.leash=free; loadPano(lobbie.swf?xml_file=lobbie.xml";
myArray[2] = "pano.leash=free; loadPano(pileta.swf?xml_file=pileta.xml";
myArray[3] = "pano.leash=free; loadPano(bardia.swf?xml_file=bardia.xml";
myArray[4] = "pano.leash=free; loadPano(restaurant.swf?xml_file=restaurant.xml";
myArray[5] = "pano.leash=free; loadPano(suite.swf?xml_file=suite.xml";
myArray[6] = "pano.leash=free; loadPano(classic.swf?xml_file=classic.xml";
for (i=1; i<=6; i++) {
var bot:MovieClip = eval("btn_"+i);
//////
bot.onRelease = function() {
_lc.send(masterSlot,"execute",myArray[this._name.slice(4,5)]);
};
}

Please some help. Thanks

Denis
05-30-2007, 02:34 PM
It's hard to understand why it's not working. Possible it's because the controller loads before the controlled application? You can try to make some pause before connection.

Also you can check examples/controller example from FPP package. It is debugged application. :)

Bernie
05-31-2007, 03:59 PM
Hi Denis

I have already try it but it is not working.
I think that the xml is loading after the controller. Can it be?
Is there an other way to load de xml or to set the localconnection?

Is it possible that swfobject cause this effect?

Thanks for the quick replay

Denis
06-01-2007, 10:39 AM
If the example is not working, there can be only one: something with security. Try to run it online (online pages in browser use different security settings). Another way is to try ExternalInterace, Adobe tell this is more reliable interface.

Maybe some error messages?