How to pass an AS3 array into krpano?

  • I'm trying to make an array that is created in a plugin accessible from krpano actions.

    I've read the notes on Kinterface_array vs array here:
    Array in AS3
    This shows how to go the other way around; from an "array" object in krpano to an array in AS3 (using kinterface_array.getArray()). However I have not yet found out how to go from AS3 to krpano.

    This does not seem to create an array at all:

    var destVarName:String = "testvar"
    var myArray:Array = [11,12,13,14,15,16];
    this.krpano.set(destVarName, myArray);

    The resulting variable in krpano looks more like a string; testvar.count is not populated, and testvar[N] (where N is any numeric value) traces as "11,12,13,14,15,16"

    This somewhat less naive approach doesn't work either:

    Any hints? Is there a Kinterface_array::setArray() function?

  • Expanding on the matter of Kinterface_array, how do I create one from scratch in xml?

    Here's my naive approach again:

    <action name="sendwallpost">
    	set(test[item1], "abc");
    	set(test[item2], "def");

    But that results in the following traces:


    In other words: test does not seem to be an array...

  • Hi Aldo,

    I have no real answer... Just played around your request and noticed some things... Hope it can help in a way *whistling* ...

    Expanding on the matter of Kinterface_array, how do I create one from scratch in xml?

    First, I had never ear about the createarray(); action... but it seems to exist and work..
    I have tried your action and I get different results depending in how it was called...
    Here the code I had used to test:

    First, remember to refresh your browser after each action call.
    There is 3 buttons that calls the actions.
    The first one calls your action sendwallpost() and the result is as you pointed out above...
    You could call the action also clicking on the pano (<events onclick="sendwallpost();" />)...
    Then, the result is:

    INFO: [object Kinterface_dynamicitem]
    INFO: [object Kinterface_dynamicitem]
    INFO: 2

    I do not know why this happens but the result seems more logical...
    The second button calls the action action2(); and the result is similar to your action...
    If you change the events onclick by the second one that is commented, the result seems to be also more correct...
    Finaly, the third button calls the action action3(); that seems to return a correct result... It does not use the createarray(); action and the array is created by setting a value to a variable of that array... In my understanding it is the correct way to do...

    Sorry for my rudimentary explanation *wink* ...


  • Thanks for playing around. You made some interesting discoveries which may help me on my way.

    Update: I think I have it working now, thanks again Michel

    This succesfully creates a krpano array. Note:
    this.krpano.set(destVarName+"["+i+"].value", result[i]);
    You have to wrap the value in a "property" of the array.

    Edited once, last by ahoeben (April 29, 2011 at 9:29 AM).

  • Hi,

    there are no real array[index] to value arrays in krpano,
    each array item/entry is an object and has a name and an index,

    you can create arrays, array-items and array-item-attributes (e.g. the value attribute in your example) anytime just by setting them,

    the getArray() function returns only the internal linear array of array items for quick linear access,

    best regards,

  • Hi,

    And the object.count "property" is basically just another variable, not an actual property?

    no, "object.count" would be the "count" property of the "object" object,


    I might have to write a plugin for using proper arrays for storing data then...

    you can already use the krpano arrays for storing data,
    but in krpano array items are addressable by 'name' and index,

    therefore all array items are objects with at least a name and index property
    and any additional custom properties,

    here as short:
    a krpano array => contains a count number of krpano array items
    a krpano array item => is an object that has a name, index and any custom properties,

    other 'custom arrays' could be added by plugins of course,
    but they would be not directly accessible from krpano xml,

    best regards,

Participate now!

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