Set Variable in krpano?

  • Hi,

    I have this problem with cross-flash communication. To simplify the problem, I'll say I have two plugins.

    One is a interface that uses a xml with all panorama id's stored (and lots of other information about that location), let's call this plugin the Control Center, because everything a user does, goes via this plugin. When a hotspot is pressed, it fires a flash function with a id in it. It then does some voodoo all based on that id. It matches the id it gets with an id thats stored in special xml file (not krpano's). Then it loads the next panorama based on this, and fires several events (open/close the map, color a hotspot so it looks active etc). This Control Center, once completed, will never be changed unless it's a bug and the same for every client.

    The other plugin can be any other plugin, but let's say it's a flashtextfield. This is a plugin a client can order. The plugin alsoo needs the id of the panorama thats being loaded (or is loaded). So in this case it needs the panorama id to match it with an id in the xml, so it can load the appropiate text file.

    Now this is where I am stuck. Somehow I need this panorama id. I tried several things. Some dont work, others just partly. Let me brief you through:
    1) I tried to fetch the function the hotspot fires. This failed. Apperently when you call a flash function within krpano. It stops as soon as it gets received. And the control center already received it.
    2) I tried to dispatch an event after the controlcenter is done. The event is received by the other plugin. But an event isn't an id. So I tried to create my own custom event that can carry a string:


    I import this class in both my plugins, but then I get a error that the dispatch event doesnt match the listener because although its the same class. It are different instances.

    3) I made a localconnection class. The controlcenter sends the id through a channel and the plugin listens to it.


    This works. BUT when you have multiple plugins all needing the id, you have to make a different channel for every plugin, thus have to update the controlcenter each time you add a plugin (or have to create a large amount of channels sending the same id, which doent help performance wise. Alsoo Localconnection is limited to 44kb of information. This isnt a problem now. But still I dont like the limit. This option is what I currently use, and Im not really happy with it.

    Then I pondered. What if I, instead of putting the location id in a seperate xml file, put it alsoo in the krpano xml file. Then when the panorama gets changed by the control center, a event will fire (onviewchange or wait(blend) by krpano). The textfield plugin will then read the unique panorama id from the krpano xml thats currently loaded.

    This raises the following questions:
    Will this work?
    How do I store a custom variable in krpano xml (I've read it somewhere but can't find the docu about it).
    How do I listen to onviewchange or wait(blend) from within the textfield plugin? Does it need a timer event or is there a better way? Because if you have 10, 20 ,30 plugins all having a timer event, listening whenever the panorama gets updates, won't help you perfomance wise :p

    Another possible solution pops in my mind, a solution concerning javascript.
    hotspot -> Controlcenter -> send javascript call - javascript -> textfield externalinterface.addcallback -> textfield updated.

    Controlcenter

    Code
    var url:URLRequest = new URLRequest("javascript:changeText(" + id + ")" );
    navigateToURL(url, "_self");


    Javascript
    no clue??? :(
    function changeText(id)
    {
    sendvariable to otherflash function
    }
    textfield

    Code
    import flash.external.ExternalInterface;
    
    
    ExternalInterface.addCallback("changeText", changeTheText);
    
    
    function changeTheText(t:String):void {
    	txtText.text = t;
    }

    Although im not sure how I can avoid page refreshes or if it sends the var to multiple plugins.
    Sorry, a very big post. But it's a problem I'm facing alot. Im trying to find the best solution, performance wise and maintence wise (leaving controlcenter as much untouched as possible and with the least amount of xml). Hope you can clear the water for me?

    Thanks!

    and btw. If you're curious about the Controlcenter and such. Go to the link in my signature. It's an old bloggy version of it. I've rewritten it completely to classes now. When you click on a hotspot. the textfield gets updated (on the right) most texts are the same, so it won't update always. And while you're in the tour, press the "i' you see near houses.

  • I have stored many variables in krpano's xml, It is pretty simple.

    For instance, if you want to store a description about a hotspot, under the description variable/attribute do as follows:
    <hotspot name="hs0" url="icon.jpg" ath="0.0" atv="0.0" description="Description here"></hotspot>

    Then you can access from the krpano_as3_interface instance in your plugin with the following code:
    var krpano = krpano_as3_interface.getInstance();
    var description = krpano.get("hotspot[hs0].description");

    Also have you looked at this page: https://krpano.com/docu/actions/#call, at the bottom it gives an example of mapping an event to a function in actionscript.

  • I have stored many variables in krpano's xml, It is pretty simple.

    For instance, if you want to store a description about a hotspot, under the description variable/attribute do as follows:
    <hotspot name="hs0" url="icon.jpg" ath="0.0" atv="0.0" description="Description here"></hotspot>

    Then you can access from the krpano_as3_interface instance in your plugin with the following code:
    var krpano = krpano_as3_interface.getInstance();
    var description = krpano.get("hotspot[hs0].description");

    Also have you looked at this page: https://krpano.com/docu/actions/#call, at the bottom it gives an example of mapping an event to a function in actionscript.

    I'm already doing that, but I need to extend it to other plugins. This is what I have:
    in krpano.xml (03_hw is the location id I need for every plugin)

    Code
    <hotspot name="loc03_hw" 
    	         url="../images/hotspots/hoogwerker_g.png"
    	         ath="-87" 
    	         atv="1"
    	         scale="0.8" alpha="0.8"
    	         zoom="true"
    			 onhover="showtext(Hoogwerker Locatie 3, STYLE);"
    			 onclick="events.changepanorama(03_hw)"
    	/>


    In the Control Center (quickly simplified, so mind the syntax faults) :

    So somehow I got this location id that gets sends to undetermined number of plugins. The hotspot can only send one, and that one is reservered for the control center plugin. (I dont want to make a seperate action for every possible plugin, iow events.updatetext(03_hw), events.preloadstuff(03_hw), events.someotherthingy(03_hw).

    So my question would be, how can I send this ID, to undetermined/inifite number of plugins, without adding either a enormous list of actions for every plugin. I want the id so I can load for instance a text based on that location, preload images/movies, alter the menu etc.

  • you can iterate through all of the added plugins in actionscript as follows:
    var count:int = krpano.get("plugins.count");
    for(var i:int = 0; i < count; i++) {
    krpano.set("plugins[" + i + "].location_id", nextlocation);
    }

    You could call this loop from your ChangePanorama function so that all of the plugins, no matter how many there are, have the same location_id that your ChangePanorama function has.
    To get the location_id on the other end from the plugin code, you should be able to access it with krpano.get("plugin[myname].location_id"). You could also trigger an event during the loop that could coorespond to a function in the plugin.

  • Hi, wow, a lot questions, I hope I can answer all

    I import this class in both my plugins, but then I get a error that the dispatch event doesnt match the listener because although its the same class. It are different instances.

    did you declare the class at global scope/package (like in the krpano_as_interface),
    then it should be possible to use in several plugins...


    How do I store a custom variable in krpano xml (I've read it somewhere but can't find the docu about it).

    just declare it in the xml or dynamically via set() (e.g. krpano.set("plugin[name].myvar", value);)
    you could also declare/store variables at global or hotspot scope,


    How do I listen to onviewchange or wait(blend) from within the textfield plugin? Does it need a timer event or is there a better way? Because if you have 10, 20 ,30 plugins all having a timer event, listening whenever the panorama gets updates, won't help you perfomance wise :p

    for the "onviewchange" event you need at least the 1.0.8 beta 7 version,
    you could assign a own as3 function to this event, and send from the functions events to all your plugins/hotspots,

    here something currently undocumented:
    to get the parent layer of the plugins and hotspots, where you can send the events:

    Code
    var hotspotlayer:Sprite = krpano.get("hotspot.layer");
    var pluginlayer:Sprite = krpano.get("plugin.layer");


    e.g.
    plugin as3 code:

    but note - the "onviewchange"is called every single move, it can happen
    up to 60 times per second,

    or do you mean when a new xml was loaded?
    for this you could use the "onxmlcomplete" event,

    (btw - a great tour in your signature! )

    best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!