View Full Version : Pass mouseClick throgh hotspot to underlying swf
blogbod
11-16-2007, 02:15 AM
Hi,
How can you pass mouse clicks (Keyboard events) to a swf in a hotspot, and when you are finished with the swf send a onClick back to pano?
Scott Witte
11-18-2007, 01:19 AM
How can you pass mouse clicks (Keyboard events) to a swf in a hotspot, and when you are finished with the swf send a onClick back to pano?
If the swf is the hotspot it can automatically handle mouse events. Examples are controller.swf and mp3player.swf. To communicate from the swf to FPP I think you will need to usw locallConnect (as with controller.swf) or javascript. There may be another way but I haven't gotten that far in my AS3 education :(
zleifr
11-18-2007, 01:33 AM
To commicate from the hotspot to FPP, you can use localConnection, externalInterace/javascript (I think), or direct calls. Check flvplayer.fla for an example, and here is the relevant code:
loaderInfo.addEventListener(Event.INIT, initHandler);
function initHandler (event:Event) {
if (loaderInfo.loader!=null) {
// get link to hotspot sprite:
movie = loaderInfo.loader.movie;
// get link to hotspot control object:
hotspot = loaderInfo.loader.hotspot;
// example how to change hotspot's properties:
// hotspot.saturation = -1;
// hotspot.rotation = 45;
// get link to hotspots plugin object:
hotspots = loaderInfo.loader.hotspots;
// example how to use it:
// hotspots.execute("pano.pan=45,1000,elastic;pano.tilt=30,1200,elastic ;");
// flv player uses dynamic sound channel, use timer to bind it to panorama soundTransform.
sTimer = new Timer(50);
sTimer.addEventListener("timer", copyParams);
sTimer.start();
// add your own event listener:
movie.addEventListener(MouseEvent.CLICK, doClick);
// define remove function (will fire on unload)
loaderInfo.loader.remove = remove;
}
}
So you use hotspots.execute() to get things done, as long as hotspots is properly defined. You should be able to even execute custom functions from the xml, and things like that.
cheathamlane
11-18-2007, 02:09 AM
OK... I'll admit to being stymied by the targeting here. It seems like in every example, the targeting path for hotspots or the panorama is different.
If I load a SWF as a plugin, I can access it just fine from FPP. If I load it as a hotspot, I can have it do things with a localConnection.
I can't seem to do both.
What's the proper targeting to, say, load a new panorama FROM a plugin? My eyes are blurry from reading all the posts here, and I have missed something somewhere.
(blogbod, sorry if I hijacked your post)
zleifr
11-18-2007, 02:25 AM
hotspots.execute() should do it from either, but the address of the hotspots object is different depending on where you are defining it from:
---------------From a hotspot:
loaderInfo.addEventListener(Event.INIT, initHandler);
function initHandler (event:Event) {
if (loaderInfo.loader!=null) {
hotspots = loaderInfo.loader.hotspots;
}
}
----------------From a plugin:
function init (panoMain:Object) {
panoController = panoMain;
if (panoMain.addExternal(this)) {
waitTimer = new Timer(50);
waitTimer.addEventListener(TimerEvent.TIMER, waitHotspots, false, 0, true);
waitTimer.start();
}
}
// wait for Hotspots plugin to load before starting tooltips
function waitHotspots (event:Event) {
if (panoController.externals.hotspots!=null) {
waitTimer.stop();
waitTimer = null
hotspots = panoController.externals.hotspots;
hotspots.addEventListener(MouseEvent.MOUSE_OVER, doOver, false, 0, true);
hotspots.addEventListener(MouseEvent.MOUSE_OUT, doOut, false, 0, true);
}
}
Those both will give you ways to define the hotspots object and a bit more. The first is from flvplayer.fla and the second is from Denis' tooltips.fla
cheathamlane
11-18-2007, 02:38 AM
Huh, OK.
:)
I'll keep plugging away. The code you pasted in is what I've been poring over for a while. There's some logical disconnect I'm making, I guess.
I still don't understand why my SWF fails to make a localConnection (or masterConnection, if you read the trace) when loaded as a plugin, but does fine as a hotspot. Nor do I get the targeting reference in the above code (the bottom 2 examples).
[got your other post, btw -- thanks. :) ]
zleifr
11-18-2007, 02:47 AM
LocalConnection fails when loaded as a plugin because it starts trying to make the connection before hotspots.swf is ready to respond, as it is loaded in parallel with hotspots.swf. If you use a timer like in the second (CORRECTED) example above for plugins, and then branch off into starting the localConnection where hotspots is defined, then localConnection will work fine.
And as for the targeting code above in the second example for plugins, it was wrong, and is now correct.
cheathamlane
11-18-2007, 04:27 AM
zleifr:
Thanks for the update... you've gone way beyond any help I expected. I think with your corrected post, I'm well on my way. I'l keep you posted of my success. :)
Cheers,
Scott Witte
11-18-2007, 05:53 AM
zleifr,
These are some great insights you have provided! While still a bit beyond me I know this will help my understanding and learning tremendously. Thanks!!
LocalConnection fails when loaded as a plugin because it starts trying to make the connection before hotspots.swf is ready to respond....
What about using a try / catch block? The localConnection.send can simply fail and try again however many ms later the next time it is called. At least I think that is how it worked for me on a SWF I'm programing.
zleifr
11-18-2007, 06:14 AM
Scott Witte: I don't know whether a try / catch block would work (it might), but I do know that it would be wasting time on trying / catching, which is could be using to load everything, although, I am not sure it would be noticeable, so let's just say it would be more elegant to use a timer, (and even more so to use an event), because that cuts down on the effort the computer uses on trying.
Basically all you would need it this below to use the timer
function init (panoMain:Object) {
panoController = panoMain;
if (panoMain.addExternal(this)) {
waitTimer = new Timer(50);
waitTimer.addEventListener(TimerEvent.TIMER, waitHotspots, false, 0, true);
waitTimer.start();
}
}
// wait for Hotspots plugin to load before starting tooltips
function waitHotspots (event:Event) {
if (panoController.externals.hotspots!=null) {
waitTimer.stop();
waitTimer = null
startLocalConnection();
}
}
And then, startLocalConnection() has the beginning connection code from the controller rolled into it, which is, I believe, not having controller in front of me now, all the code not already encapsulated in a function up to the end of the connection code.
cheathamlane
11-18-2007, 04:39 PM
...And then, startLocalConnection() has the beginning connection code from the controller rolled into it, which is, I believe, not having controller in front of me now, all the code not already encapsulated in a function up to the end of the connection code.
OK... Having a little more success here, now. :) I'll post the entire set of code below for a combobox which has its label/data info given to it by your FPP XML. Below that I'll post the interesting bits of XML.
I'm still unable to have the dropdown menu load a panorama -- the "master slot" is always returned as "null", which makes me think a connection isn't really being made?
FLA:
//make sure your combobox is set to editable
/*begin PLUGIN block */
// Implements plugin interface.
// Two required public parameters:
// id:String, version:String
// Four required public functions:
// init(Object):void, newPano(Object):void, newParams(String):void, remove(void):void
var id:String="cl_dropdownmenu";
var version:String=".1";
var pano:Object=null;
var panorama:Object;
//
var panoController:Object=null;
var waitTimer;
//
function init (panoMain:Object) {
panoController = panoMain;
//from zleifr:
if (panoMain.addExternal(this)) {
waitTimer = new Timer(50);
waitTimer.addEventListener(TimerEvent.TIMER, waitHotspots, false, 0, true);
waitTimer.start();
trace("----###############--------");
trace("WAIT TIMER ");
trace("----###############--------");
}
}
// wait for Hotspots plugin to load before starting tooltips
function waitHotspots (event:Event) {
if (panoController.externals.hotspots!=null) {
waitTimer.stop();
waitTimer = null
startLocalConnection();
trace("----###############--------");
trace("startLocalConnection ");
trace("----###############--------");
}
}
//
function newPano (link:Object) {
pano = link;
if (pano.loadersState!=null) {
}
}
/* IF getting info from a plugin xml element called "cl_dropdownmenu" */
function newParams (str:String) {
trace("----###############--------");
trace("NEWPARAMS from XML ELEMENT: "+str);
trace("----###############--------");
}
//function setAttribute (name:String, value:String, time:String=null, type:String=null, onDoneFunction:String=null, onInterruptFunction:String=null, relative:int=0) {
function setAttribute (name:String, theLabel:String, theData:String, theInfo:String, onDoneFunction:String=null, onInterruptFunction:String=null, relative:int=0) {
_cb.addItem({label:theLabel, data:theData});
trace("----###############--------");
trace("name : "+name+" theLabel : "+theLabel+" theData : "+theData+" theInfo : "+theInfo);
trace("----###############--------");
}
//
function remove () {
//
}
/* end new PLUGIN block*/
/* test moving this here */
var _lc:LocalConnection;
/* */
/* ORIGINAL CONNECTION CODE */
// Use the same name in spots.xml: <global controller="lc_test">
// Better use different controller names for different panorama applications
var controllerName:String = "cl_dropdown_connection";
// Master slot name:
var masterSlot:String;
// Slave slot name:
var slaveSlot:String;
function startLocalConnection () {
// Begin of connection code (better use it as is).
var dumpSlot = controllerName+"_dump_"+Math.random();
//var _lc:LocalConnection = new LocalConnection(); //original
_lc = new LocalConnection();
_lc.allowDomain("*");
_lc.connect(dumpSlot);
_lc.addEventListener(StatusEvent.STATUS, onStatus);
_lc.client = this;
function onStatus(info) {
if (info.level == "error") {
trace("No master connection detected.");
_lc.close();
_lc = null;
}
};
function setSlot(slot) {
masterSlot = controllerName+"_master_"+slot;
slaveSlot = controllerName+"_slave_"+slot+"_"+Math.random();
_lc.close();
_lc.connect(slaveSlot);
startWatch();
trace("----###############--------");
trace("SET slaveSlot: "+slaveSlot);
trace("SET masterSlot: "+masterSlot);
trace("----###############--------");
};
_lc.send(controllerName+"_master_0", "getSlot", dumpSlot);
// end of connecion code
} //end startLocalConnection
var panoName:String; // current pano name
var panoBusy:Boolean; // true if panorama is loading or a transition effect is in process
var timer:Timer; // timer
// start watching parameters "panoName" and "panoBusy":
function startWatch () {
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, sendQuery);
timer.start();
}
// send query:
function sendQuery (event:Event) {
// 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");
trace("----###############--------");
trace("FROM SEND QUERY!!");
trace("----###############--------");
}
// listener function:
function callback(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;
//if (panoName != _cb.selectedItem.data) {
if (panoName != _cb.selectedItem.data) {
var n = _cb.length;
for (var i=0; i<n; i++) {
if (_cb.getItemAt(i).data==panoName) {
_cb.selectedIndex = i;
}
}
}
};
// register change handler for the combobox:
_cb.addEventListener("change", changed);
function changed(event:Event) {
// roll back changes if panorama loader is busy:
if (panoBusy) {
return;
}
panoBusy = true;
// load new swf file:
loadPano(_cb.selectedItem.data);
//
trace("----###############--------");
trace("I CHANGED, REALLY!");
trace("panoBusy : "+panoBusy);
trace("_cb.selectedItem.data : "+_cb.selectedItem.data);
trace("----###############--------");
}
// load new panorama:
function loadPano(name) {
if (masterSlot != null) {
//my panorama names come in as stg like: images/mypano/mypano,
//but i put my xml for this tour at root of tour, so need to
//parse the xml file name to just: mypano
var nameOnly:Array = name.split("/");
var theXMLFileName:String = nameOnly[2];
trace("----###############--------");
trace("XML: "+ theXMLFileName);
trace("----###############--------");
//
_lc.send(masterSlot, "execute", "loadPano(?panoName="+name+"&xml_file="+theXMLFileName+".xml&,1000,stripes);");
}
trace("----###############--------");
trace("masterSlot : "+masterSlot); //always returns as "null"
trace("----###############--------");
}
XML (formatted for readability):
<panorama>
<parameters>
layer_20 = files/hotspots.swf
layer_80 = files/MY_COMBOBOX.swf
</parameters>
<cl_dropdownmenu>
menuItem=My Cool Pano,images/myPano_1/myPano_1,blahblahbblah1
menuItem2=My Other Cool Pano,images/myPano_2/myPano_2,blahblahbblah2
</cl_dropdownmenu>
<hotspots>
<global
LocalConnectionID="
cl_dropdown_connection
"
onStart="
setDropdownMenuOnStart;
"
setDropdownMenuOnStart="
external.cl_dropdownmenu.menuItem=My Cool Pano,images/myPano_1/myPano_1,blahblahbblah1,,,;
external.cl_dropdownmenu.menuItem2=My Other Cool Pano,images/myPano_2/myPano_2,blahblahbblah2,,,;
"
>
<pano leash="free"></pano>
<!--// DROPDOWN MENU: unused for now
<spot static="1"
sAlign="RT"
align="RT"
staticX="-110"
staticY="46"
blockMouse="1"
url="files/MY_COMBOBOX.swf"
/>
//-->
</global>
</hotspots>
</panorama>
cheathamlane
11-18-2007, 05:29 PM
And, what I see in Flash Tracer's output (with some hotspot load/unloads removed for readability's sake):
CubePanorama v2.2 loaded.
Load layer 80: files/controller-test2-plugin.swf
Load layer 20: files/hotspots.swf
cl_dropdownmenu v.1 successfully loaded.
----###############--------
NEWPARAMS from DROPDOWNMENU:
menuItem1=images/myPano_1/myPano_1
menuItem2=images/myPano_2/myPano_2
----###############--------
----###############--------
WAIT TIMER
----###############--------
Hotspots v2.2 successfully loaded.
Load 0: images/myPano_1/myPano_1_f.jpg
Load 1: images/myPano_1/myPano_1_r.jpg
Load 2: images/myPano_1/myPano_1_b.jpg
Load 3: images/myPano_1/myPano_1_l.jpg
Load 4: images/myPano_1/myPano_1_u.jpg
Load 5: images/myPano_1/myPano_1_d.jpg
----###############--------
startLocalConnection
----###############--------
No master connection detected.
----###############--------
I snipped out various hotspot load/unload statements here
----###############--------
LocalConnection 'cl_dropdown_connection_master_0' connected
----###############--------
I snipped out various hotspot load/unload statements here
----###############--------
Execute global: setDropdownMenuOnStart
Execute global: external.cl_dropdownmenu.menuItem=My Cool Pano,images/myPano_1/myPano_1,blahblahbblah1,,,
----###############--------
name : menuitem theLabel : My Cool Pano theData : images/myPano_1/myPano_1 theInfo : blahblahbblah1
----###############--------
Execute global: external.cl_dropdownmenu.menuItem2=My Other Cool Pano,images/myPano_2/myPano_2,blahblahbblah2,,,
----###############--------
name : menuitem2 theLabel : My Other Cool Pano theData : images/myPano_2/myPano_2 theInfo : blahblahbblah2
----###############--------
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AttributesBox/::loadComplete()
----###############--------
I CHANGED, REALLY!
panoBusy : false
_cb.selectedItem.data : images/Harvests_1_3/Harvests_1_3
----###############--------
----###############--------
masterSlot : null
----###############--------
zleifr
11-19-2007, 03:26 AM
patrick: you are getting there. you need to move all the var statement out of startlocalconnection function, so that they will be defined any accessable by any other function. put them above. move the functions out as well--onStatus and setSlot. The last statement in startlocalconnection should be _lc.send... statement at the end of the connection code.
SO, the newly arranged connection code has all the var statements not contained in the function, nor the setslot and onstatus functions. at the end of startlocalconnection, it should execute the _lc.send statement, which either results in failure and calling onstatus, or in success when fpp calls back asking for setslot.
cheathamlane
11-19-2007, 04:39 AM
Hey zleifr:
Yeah, I thought about that, and tried it -- but still no joy... :(
The more I think about it, it must be a timing issue, and/or couple with an incorrect call to loadPano() from a plugin. Unsure, though.
/*begin new PLUGIN block */
// Implements plugin interface.
// Two required public parameters:
// id:String, version:String
// Four required public functions:
// init(Object):void, newPano(Object):void, newParams(String):void, remove(void):void
var id:String="cl_dropdownmenu";
var version:String=".1";
var pano:Object=null;
var panorama:Object;
//
var panoController:Object=null;
var panoParsedtimer;
//
//local connection vars
/* test moving this here */
var controllerName:String = "cl_dropdownmenu";
var _lc:LocalConnection;
//var _lc:LocalConnection= new LocalConnection();
var dumpSlot = controllerName+"_dump_"+Math.random();
// Master slot name:
var masterSlot:String;
// Slave slot name:
var slaveSlot:String;
//
var panoName:String; // current pano name
var panoBusy:Boolean; // true if panorama is loading or a transition effect is in process
var timer:Timer; // timer
//
function init (panoMain:Object) {
panoController = panoMain;
}
//
/* if getting info from a plugin xml element */
function newParams (str:String) {
trace("----###############--------");
trace("NEWPARAMS from DROPDOWNMENU: "+str);
trace("----###############--------");
}
//function setAttribute (name:String, value:String, time:String=null, type:String=null, onDoneFunction:String=null, onInterruptFunction:String=null, relative:int=0) {
function setAttribute (name:String, theLabel:String, theData:String, theInfo:String, onDoneFunction:String=null, onInterruptFunction:String=null, relative:int=0) {
_cb.addItem({label:theLabel, data:theData});
trace("----###############--------");
trace("name : "+name+" theLabel : "+theLabel+" theData : "+theData+" theInfo : "+theInfo);
trace("----###############--------");
}
//
function remove () {
//
}
//
function newPano (link:Object) {
pano = link;
if (pano.loadersState!=null) {
/* TESTING */
panoParsedtimer = new Timer(100);
panoParsedtimer.addEventListener(TimerEvent.TIMER, checkPanoParsed);
panoParsedtimer.start();
}
}
//
function checkPanoParsed (e:Event) {
if ( pano.parsed ) {
panoParsedtimer.stop();
panoParsedtimer = null
startLocalConnection();
}
}
/* end new PLUGIN block*/
/* */
/* ORIGINAL CONNECTION CODE */
//
function onStatus(info) {
if (info.level == "error") {
trace("No master connection detected.");
_lc.close();
_lc = null;
}
};
//
function setSlot(slot) {
masterSlot = controllerName+"_master_"+slot;
slaveSlot = controllerName+"_slave_"+slot+"_"+Math.random();
_lc.close();
_lc.connect(slaveSlot);
trace("----###############--------");
trace("SET slaveSlot: "+slaveSlot);
trace("SET masterSlot: "+masterSlot);
trace("----###############--------");
startWatch();
};
//
function startLocalConnection () {
//var _lc:LocalConnection = new LocalConnection(); //original
_lc = new LocalConnection();
_lc.allowDomain("*");
_lc.connect(dumpSlot);
_lc.addEventListener(StatusEvent.STATUS, onStatus);
_lc.client = this;
_lc.send(controllerName+"_master_0", "getSlot", dumpSlot);
// end of connecion code
} //end startLocalConnection
//
// start watching parameters "panoName" and "panoBusy":
function startWatch () {
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, sendQuery);
timer.start();
}
// send query:
function sendQuery (event:Event) {
// 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");
trace("----###############--------");
trace("FROM SEND QUERY!!");
trace("----###############--------");
}
// listener function:
function callback(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;
//if (panoName != _cb.selectedItem.data) {
if (panoName != _cb.selectedItem.data) {
var n = _cb.length;
for (var i=0; i<n; i++) {
if (_cb.getItemAt(i).data==panoName) {
_cb.selectedIndex = i;
}
}
}
};
// register change handler for the combobox:
_cb.addEventListener("change", changed);
function changed(event:Event) {
trace("----###############--------");
trace("I CHANGED, REALLY!");
trace("panoBusy : "+panoBusy);
trace("_cb.selectedItem.data : "+_cb.selectedItem.data);
trace("----###############--------");
// roll back changes if panorama loader is busy:
if (panoBusy) {
return;
}
panoBusy = true;
// load new swf file:
//loadPano(_cb.selectedItem.data);
loadPano(_cb.selectedItem.data);
}
// load new panorama:
function loadPano(name) {
trace("----###############--------");
trace("masterSlot : "+masterSlot);
trace("----###############--------");
if (masterSlot != null) {
//my panorama names come in as stg like: images/mypano/mypano,
//but i put my xml for this tour at root of tour, so need to
//parse the xml file name to just: mypano
var nameOnly:Array = name.split("/");
var theXMLFileName:String = nameOnly[2];
trace("----###############--------");
trace("XML: "+ theXMLFileName);
trace("----###############--------");
//
_lc.send(masterSlot, "execute", "loadPano(?panoName="+name+"&xml_file="+theXMLFileName+".xml&,1000,stripes);");
}
}
zleifr
11-19-2007, 02:40 PM
well in the flashlog does it say that the localconnection has been established?
If not, then it's an issue with that. If the localconnection has been established then it is a problem with the loadPano command.
Describe what it is doing now, if you would.
cheathamlane
11-19-2007, 03:22 PM
Hey there:
Yes, it says a localConnection has been established (though I think this is coming from FPP and not my trace() code). When I go to use the dropdown menu, "masterSlot" returns as null.
NOW I notice that when all the vars are declared at root, suddenly the plugin in question becomes unknown!
I'll see if I can attach the FLA. OK, uploaded to:
http://cheathamlane.net/tests/test2h-plugin.fla.zip
~750kb (why is it so huge?! Weird :) )
cheathamlane
11-19-2007, 10:47 PM
I've been trying just about every code permutation I can think of or come up with for this and still no luck... Anyone taken a peek or have any insight?
zleifr
11-20-2007, 12:50 AM
Tweaked the timer a bit and it is working.
I don't know why it is 420k so I am just pasting the actionscript below:
/*begin new PLUGIN block */
// Implements plugin interface.
// Two required public parameters:
// id:String, version:String
// Four required public functions:
// init(Object):void, newPano(Object):void, newParams(String):void, remove(void):void
var id:String="cl_dropdownmenu";
var version:String=".1";
var pano:Object=null;
var panorama:Object;
//
var panoController:Object=null;
var panoParsedtimer;
var hotspots:Object;
var waitTimer:Timer;
//
//local connection vars
/* test moving this here */
var controllerName:String = "cl_dropdownmenu";
var _lc:LocalConnection;
//var _lc:LocalConnection= new LocalConnection();
var dumpSlot = controllerName+"_dump_"+Math.random();
// Master slot name:
var masterSlot:String;
// Slave slot name:
var slaveSlot:String;
//
var panoName:String; // current pano name
var panoBusy:Boolean; // true if panorama is loading or a transition effect is in process
var timer:Timer; // timer
//
function init (panoMain:Object) {
panoController = panoMain;
if (panoMain.addExternal(this)) {
waitTimer = new Timer(50);
waitTimer.addEventListener(TimerEvent.TIMER, waitHotspots, false, 0, true);
waitTimer.start();
}
}
function waitHotspots (event:Event) {
if (pano.parsed) {
waitTimer.stop();
waitTimer = null
startLocalConnection();
}
}
//
/* if getting info from a plugin xml element */
function newParams (str:String) {
trace("----###############--------");
trace("NEWPARAMS from DROPDOWNMENU: "+str);
trace("----###############--------");
}
//function setAttribute (name:String, value:String, time:String=null, type:String=null, onDoneFunction:String=null, onInterruptFunction:String=null, relative:int=0) {
function setAttribute (name:String, theLabel:String, theData:String, theInfo:String, onDoneFunction:String=null, onInterruptFunction:String=null, relative:int=0) {
_cb.addItem({label:theLabel, data:theData});
trace("----###############--------");
trace("name : "+name+" theLabel : "+theLabel+" theData : "+theData+" theInfo : "+theInfo);
trace("----###############--------");
}
//
function remove () {
//
}
//
function newPano (link:Object) {
pano = link;
}
//
/* end new PLUGIN block*/
/* */
/* ORIGINAL CONNECTION CODE */
//
function onStatus(info) { trace("Arrived at onStatus, not good");
if (info.level == "error") {
trace("No master connection detected.");
_lc.close();
_lc = null;
}
};
//
function setSlot(slot) { trace("Arrived at setSlot");
masterSlot = controllerName+"_master_"+slot;
slaveSlot = controllerName+"_slave_"+slot+"_"+Math.random();
_lc.close();
_lc.connect(slaveSlot);
trace("----###############--------");
trace("SET slaveSlot: "+slaveSlot);
trace("SET masterSlot: "+masterSlot);
trace("----###############--------");
startWatch();
};
//
function startLocalConnection () {
//var _lc:LocalConnection = new LocalConnection(); //original
_lc = new LocalConnection();
_lc.allowDomain("*");
_lc.connect(dumpSlot);
_lc.addEventListener(StatusEvent.STATUS, onStatus);
_lc.client = this;
_lc.send(controllerName+"_master_0", "getSlot", dumpSlot);
// end of connecion code
} //end startLocalConnection
//
// start watching parameters "panoName" and "panoBusy":
function startWatch () {
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, sendQuery);
timer.start();
}
// listener function:
function callback(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;
//if (panoName != _cb.selectedItem.data) {
if (panoName != _cb.selectedItem.data) {
var n = _cb.length;
for (var i=0; i<n; i++) {
if (_cb.getItemAt(i).data==panoName) {
_cb.selectedIndex = i;
}
}
}
};
// send query:
function sendQuery (event:Event) {
// 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");
trace("----###############--------");
trace("FROM SEND QUERY!!");
trace("----###############--------");
}
// register change handler for the combobox:
_cb.addEventListener("change", changed);
function changed(event:Event) {
trace("----###############--------");
trace("I CHANGED, REALLY!");
trace("panoBusy : "+panoBusy);
trace("_cb.selectedItem.data : "+_cb.selectedItem.data);
trace("----###############--------");
// roll back changes if panorama loader is busy:
if (panoBusy) {
return;
}
panoBusy = true;
// load new swf file:
//loadPano(_cb.selectedItem.data);
loadPano(_cb.selectedItem.data);
}
// load new panorama:
function loadPano(name) {
trace("----###############--------");
trace("masterSlot : "+masterSlot);
trace("----###############--------");
if (masterSlot != null) {
//my panorama names come in as stg like: images/mypano/mypano,
//but i put my xml for this tour at root of tour, so need to
//parse the xml file name to just: mypano
var nameOnly:Array = name.split("/");
var theXMLFileName:String = nameOnly[2];
trace("----###############--------");
trace("XML: "+ theXMLFileName);
trace("----###############--------");
//
_lc.send(masterSlot, "execute", "loadPano(?panoName="+name+"&xml_file="+theXMLFileName+".xml&,1000,stripes);");
}
}
cheathamlane
11-20-2007, 01:28 AM
Cool Zephyr -- thanks...
I just copied and pasted your code into a new FLA document, using the AS3 ComboBox. When I save to SWF, and use in my presentation I get similar results to before (not working).
Here's part of the results from Flash Tracer:
Arrived at onStatus, not good
No master connection detected.
And then later:
masterSlot : null
I've created a new FLa from scratch, and placed your code in it along with a new-from-the-library Combobox. See it at:
http://cheathamlane.net/tests/test2j-plugin.fla.zip
Thanks for your continued attempts -- if it is working on your end, I'm mystified. Do you have an example FLA to share? I can't imagine what the difference is... Weird!
vBulletin® v3.7.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.