Extending PanoSalado
This is general description of creating PanoSalado plugins/extensions
Introduction
PanoSalado application is basically group of *.swf files stacked one atop another. All layers are aggregated by ModuleLoader.swf, and PanoSalado.swf is one of those layers. In order to perform communication between layers one needs to refer to ModuleLoader. To send data between layers, first one needs to add event listerner to ModuleLoader instance, then dispatch event from same ModuleLoader. Event that pass data between layers is defined in zephyr.BrodcatsEvent.as
Plugin file can be inserted into application by adding reference to it as new layer node into configuration *.xml file. Layer nodes are described with following attributes: unique id, url to *.swf file and depth, where highest value determines most ontop layer.
<layer id="MyPlugin" url="plugins/MyPlugin.swf" depth="5" />
Communication Panosalado to plugin
dispatching BroadcastEvent
BroadcastEvent is dispatched from PanoSalado or any other layer with following code:
// in PanoSalado.as
dispatchBroadcast(BroadcastEvent.TYPE, "param1=value1","param2=value2,ect");
// in ModuleLoader.as and in other layers
moduleLoader.dispatchEvent(new BroadcastEvent(BroadcastEvent.TYPE, {param1:value1, param2:value2, ect}));
// where BroadcastEvent.TYPE is static constant string described in BroadcastEvent.as
Active event types and arguments they pass in "info: object:
used for notifying autorotation changes
- AUTOROTATION_ON
- AUTOROTATION_OFF
used for notifying entering/exiting fullscreen
- ENTER_FULLSCREEN
- EXIT_FULLSCREEN
used by Flex interface
- STYLE_SHEET_LOADED
- OVERRIDE_STYLE_SHEET_LOADED
- STYLING_COMPLETE
used by Cursor plugin
used by PanoSalado
used by PanoSaladoLoadMeter plugin
- LOAD_PROGRESS (id:String, percentLoaded:int)
- LOADING_SPACE (loadingSpace:String)
- SPACE_LOADED (spaceLoaded:String)
Custom dispatching of BroadcastEvent can be done in two ways:
From *.xml file configuration file from speudo-function e.g. by clicking on hotspot. More at PanoSalado public functions
<hotspot id="hotspot1" onClick="dispatchBroadcast:myEvent,param1=hello,param2=world">
[...]
From source code of one of application layers
moduleLoader.dispatchEvent(new BroadcastEvent("myEvent", {param1:value1, param2:value2, ect.}));
catching BroadcastEvent
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.system.ApplicationDomain;
import zephyr.BroadcastEvent;
import flash.text.TextField;
public class Template extends Sprite {
private var textField:TextField;
private var ModuleLoader:Class;
private var moduleLoader:Object;
public function Template(){
addEventListener(Event.ADDED_TO_STAGE, stageReady, false, 0, true);
}
private function stageReady (e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, stageReady);
ModuleLoader = ApplicationDomain.currentDomain.getDefinition("ModuleLoader") as Class;
moduleLoader = ModuleLoader(parent);
this.textField = new TextField();
this.addChild(textField);
moduleLoader.addEventListener("myEvent", myEventHandlerFunction, false, 0, true);
}
public function myEventHandlerFunction(e:BroadcastEvent):void{
if (e.info){
var infoObject:Object = e.info as Object;
this.textField.text = infoObject.param1 + " " + infoObject.param2;
}
}
}
}
Communication plugin to PanoSalado
This is done by executing public functions contained in PanoSalado.as
Availbe functions are listed at PanoSalado public functions
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.system.ApplicationDomain;
import flash.utils.Dictionary;
import zephyr.BroadcastEvent;
public class Template2 extends Sprite {
private var moduleLoader:Object;
private var ModuleLoader:Class;
private var PanoSalado:Class;
private var layerByName:Dictionary;
private var panoSalado:Object;
public function Template2():void {
addEventListener(Event.ADDED_TO_STAGE, stageReady, false, 0, true);
}
private function stageReady(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, stageReady);
BroadcastEvent = ApplicationDomain.currentDomain.getDefinition("zephyr.BroadcastEvent") as Class;
ModuleLoader = ApplicationDomain.currentDomain.getDefinition("ModuleLoader") as Class;
moduleLoader = ModuleLoader(parent);
moduleLoader.addEventListener(BroadcastEvent.ALL_LAYERS_LOADED, layersReady, false, 0, true);
}
private function layersReady(e:Event):void {
PanoSalado = ApplicationDomain.currentDomain.getDefinition("PanoSalado") as Class;
layerByName = Dictionary( moduleLoader["layerByName"] );
panoSalado = PanoSalado( layerByName["PanoSalado"] );
buildAll();
}
private function buildAll():void{
this.button = new Sprite();
button.graphics.beginFill(0x00FF00);
button.graphics.drawRect(0,0100,100);
button.graphics.endFill();
this.addChild(button);
button.addEventListener(MouseEvent.CLICK, clicked);
}
private function clicked(e:Event):void {
var space:String = "existing_space"
panoSalado.execute("loadSpace:" + space);
}
}
}
Getting parameters from *.xml configuration file
Example code in *.xml file
<layer id="Template3" url="plugins/Template3.swf" depth="8"
param1 = "xml params"
param2 = "12345"
>
<child label="first">files/file1.jpg</child>
<child label="second">files/file2.jpg</child>
</layer>
<layer id="PanoSalado" url="PanoSalado.swf" depth="0">
<spaces
statistics="true"
>
[...]
</spaces>
</layer> Source code getting those parameters:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.system.ApplicationDomain;
public class Template3 extends Sprite{
var param1:String;
var param2:Number;
var childLabel1:String;
var childLabel2:String;
var childFile1:String;
var childFile2:String;
var statisticsShowing:Boolean;
private var ModuleLoader:Class;
private var moduleLoader:Object;
public function Template3() {
addEventListener(Event.ADDED_TO_STAGE, stageReady, false, 0, true);
}
private function stageReady(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, stageReady);
ModuleLoader = ApplicationDomain.currentDomain.getDefinition("ModuleLoader") as Class;
moduleLoader = ModuleLoader(root.parent);
this.getSettings();
}
private function getSettings():void {
var settings: XML = moduleLoader.xmlByName["Template3"];
this.param1 = String((settings@.param1 != undefined) ? settings@.param1 : "default value");
this.param2 = Number((settings@.param2 != undefined) ? settings@.param2 : "0");
childLabel1 = String((settings.children[0] != undefined) ? settings.child[0] : "default value");
childLabel2 = String((settings.children[1] != undefined) ? settings.child[1] : "default value");
childFile1 = String((settings.child[0].@label != undefined) ? settings.child[0].@label : "default value");
childFile2 = String((settings.child[1].@label != undefined) ? settings.child[1].@label : "default value");
settings = moduleLoader.xmlByName["PanoSalado"];
this.statisticsShowing = (settings.spaces.@statistics != undefined) ? settings.spaces.@statistics == "true" : false;
}
}
}