Dynamically creating many hotspots from AS3

  • Hi there

    I'm making an AS3 plugin which requires creating a lot of hotspots dynamically (1000+), from information returned by a server. I've tried two solutions, but none of them works 100%.

    First, I tried repeatedly calling a krpano action from the AS3 plugin. This made krpano go really slow for some time and even crash because of a timeout. I also tried enabling "freezeview" while doing this, but it didn't seem to do much.

    My second try was to create an array from AS3 and then calling a krpano action which iterated over the array and created the hotspots. I created the array using the information on this thread, and the iteration was done using the "loop" action from 1.0.8.14. Unfortunately, I couldn't iterate over the entire array due to the "actions overflow".

    The last solution I can think of is to generate some krpano XML using the information I get from the server, and then use "loadxml()" to create the hotspots. However, this means that I won't be able to change the hotspots dynamically, since "loadxml" always expects a new panorama to be loaded.

    So, before trying this last solution, I'd like to know if there some "faster" way to make KRPano create a lot of hotspots, or if this is really the best way to go.

    Thanks,
    Manuel

  • Use your second try, but try using delayedcall to put the actions on different frames.
    There are frames/per second in flash, and actions that happen on a frame.
    By using a delayedcall you are queuing actions on future frames and bypassing the actions overflow limit.
    At least this is my understanding.

  • Hi,

    can you show the code that you were trying to use?

    this should be the fastest way to add and get a hotspot:

    Code
    krpano.call("addhotspot("+spotname+")");
    var hotspot:Object = krpano.get("hotspot["+spotname+"]");
    ...

    the setting of the attributes of the hotspot should be done directly in as3,
    this is faster then setting them by calling the set function and much faster then calling the set action,

    best regards,
    Klaus

  • Hi

    Thanks! I'll try that as soon as I can. In the meantime, here's the code I used on the other attempts.

    The first try was just a simple loop in as3 and a krpano action:

    AS3:

    Code
    for each(var i:Object in response.list) {
    	var krcode:String = "createSpot(" +
    		i.id+ "," +
    		i.ath + "," +
    		i.atv + "," +
    		i.info + ")";
    	kr.krpano.call(krcode);
    }

    krpano:

    Code
    <action name="createSpot">
    	addhotspot(hs-%1);
    		
    	hotspot[hs-%1].loadstyle(myspot);
    	set(hotspot[hs-%1].ath,%2);
    	set(hotspot[hs-%1].atv,%3);
    	set(hotspot[hs-%1].info,%4);
    </action>

    On the second try, I was creating an array in AS3, and then looping in krpano. For looping, I used a foreach() action, which is based on the new loop():

    as3:

    Code
    krpanoObj.createarray("newhotspots");
    newHotspotsArray = krpanoObj.newhotspots
    
    
    for each(var i:Object in response.list) {
    	var nh:Object = newHotspotsArray.createItem("hs-" + i.id);
    	nh.registerattribute("ath",i.ath);
    	nh.registerattribute("atv",i.atv);
    	nh.registerattribute("info",i.info);
    }

    krpano:

  • Are you attempting to implement tagging? You should display fewer icons that communicate the fact that there are more tags in a general area. Many of the applications ruin the aesthetics and hinder performance. You should also make a good balance between a responsive application and uneccessary function calls.

  • Just in case someone stumbles on this thread, here's how I solved it.

    I "pre-loaded" a number of invisible hotspots by creating them on an xml file like this:


    Code
    <hotspot name="panotag-pi-ts-0" style="panotag-tagspot" visible="false"/><hotspot name="panotag-pi-ts-1" style="panotag-tagspot" visible="false"/><hotspot name="panotag-pi-ts-2" style="panotag-tagspot" visible="false"/>(...)


    Then I retrieved them in AS3 using their name, and added them to a "not used" list. Whenever I needed to create a new hotspot dynamically, I got one from the "not used" list, changed its coordinates and visibility and added it to a "used" list. To remove a hotspot, I did the opposite. This was much faster than creating new hotspots.

    When there are a lot of hotspots in a panorama , krpano will get a bit slow. Therefore, I'm only showing hotspots which were in the currently visible area, and removing the others.

    The result can be seen here: http://www.digisfera.pt/panotag-example-giga

  • why my hotspots don´t apearing?

    in As3:


    private function onResultObterTodosUsuarios(e:Array):void
    {

    for (var i:int = 0; i < e.length; i++)
    {
    _krPano.call("createSpot(" +e.Id+ "," +e.PosicaoX + "," +e.PosicaoY + ")");

    };


    }

    in XML:

    <action name="createSpot">
    showlog();
    trace("createSpot");

    addhotspot(hs-%1);
    set(hotspot[hs-%1].url,mark.png);
    set(hotspot[hs-%1].ath,%2);
    set(hotspot[hs-%1].atv,%3);
    </action>

    trace:

    INFO: createSpot
    INFO: createSpot

  • Hey man,

    What´s the problem with this code please?


    for (var i:int = 0; i < e.length; i++)
    {
    //_krPano.call("showlog()"); _krPano.trace(1, "Uma vez");

    var spotname:String = "spot" + "-" + e[i].Id;
    _krPano.call("showlog()"); _krPano.trace(1, "spot" + "-" + e[i].Id ) ;
    var spot:Object = _krPano.get("hotspot[" + spotname + "]");
    _krPano.call("addhotspot(" + spotname +")");

    spot.zoom = true;
    spot.url = "mark.png";
    spot.ath =e[i].PosicaoX;
    spot.atv = e[i].PosicaoY;
    spot.onclick = function():void { _krPano.call("showlog()"); _krPano.trace(1, "spot clicked... X = " + e[i].PosicaoX ) };

    };

    the hotspots don´t appearing people!

  • Hi,

    What´s the problem with this code please?

    var spot:Object = _krPano.get("hotspot[" + spotname + "]");
    _krPano.call("addhotspot(" + spotname +")");

    wrong order - first you need the add the hotspot and then you can get it,
    then there is no hotspot with that name you will get 'null' as so the following actionscript code will fail when trying to access a 'null' object (use the DEBUG flashplayer to see such errors),

    spot.ath =e.PosicaoX;
    spot.atv = e.PosicaoY;

    the ath/atv coordinates are spherical 360/180 coordinates in degrees, using 'x/y' screen coordinates here is not correct,

    best regards,
    Klaus

Participate now!

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