• I am at the end of my wisdom and would appreciate a quick help with the createarray() command:

    Could not find anything in your forum..


    - I successfully created an array and filled it in xml
    - can read separate entries directly in as3 - krpano.get("plugin[thumbs:panos].thumb[3].url")
    - but can't bring the accessible array into an swf plugin

    here are the snippets:
    xml:

    <action name="load_pano_thumbnails">
    set(plugin[thumbs:panos].thumb[2].url,1.jpg);
    set(plugin[thumbs:panos].thumb[3].url,2.jpg);
    set(plugin[thumbs:panos].thumb[4].url,3.jpg);
    set(plugin[thumbs:panos].thumb[testy].url,4.jpg);
    set(plugin[thumbs:panos].alpha,0);
    trace(has loaded);
    </action>

    And the as3 part:
    //note: array is initialized in as3:

    plugin_object.createarray("thumb")

    function updateEvent(dataevent:DataEvent):void

    {
    krpano.trace(0, krpano.get("plugin[thumbs:panos].thumb[3].url") ); //this works like a charm
    try{
    var temp:* = krpano.get("plugin[thumbs:panos].thumb" ); //this doesn't return the array, but an 'object Kinterface_array' that I cannot access the regular array way *smile*

    krpano.trace(0, temp[3].url ); //hence, this doesn't run
    }catch(e:Error){
    krpano.trace(0, e );
    }
    }
    //end

    Is there any documentation on how to use the object kinterface_array()? or another way to be able to treat the xml generated array as an array in as3?

    Thanks for any response in advance.

  • Hi,

    first some notes for array elements:

    • array elements can be accessed by their name or a numeric index
    • when the first character of the indexname is a number then this number is interpreted as index (0 based)
    • otherwise the element is accessed by the given name
    • try to avoid mixing of numeric and names as index when defining array items in the xml!


    here a example - how to get the name of each array item with the krpano interface: (AS3 code / JS similar)

    Code
    var count:int = int( krpano.get("plugin.count") );
    var i:int;
    
    
    for (i=0; i<count; i++)
    {
       var itemname:String = krpano.get("plugin[" + i + "].name");
       // ...
       // all other attributes can be accessed by the same way
    }

    this is the standard way via the krpano interface, this works identically also in javascript!

    but with AS3 - there is also a more advanced and faster access possible
    an Array in krpano is of the internal type "Kinterface_array",
    this Array can by accessed as "Object" in AS3,

    how to use it:

    first get the internal array object via the krpano interface:

    Code
    var krpanoarray:Object = krpano.get("plugin");

    this Kinterface_array object has the following attributes and interface functions:

    attributes:

    • count
      • the number of elements in this array
      • could be changed by setting it, but warning - only reducing the size is possible (e.g. set to 0 to clear the array), increasing the count would have a undefined behavior!


    functions:

    • createItem(name:String):*
      • creates a new array item with the given name
      • returns the new item object
    • getItem(name:String):*
      • returns the item object or null if not found
      • when name is a numeric value - the name is interpreted as index (0 ... count-1)
    • getItemIndex(index:int):*
      • direct index access (faster than getItem)
      • returns the item object or null if not found
    • getArray():Array
      • returns a AS3 Array object of all array items
      • note - this Array object can be used for reading/modify items, but the Array item shouldn't be changed!
    • renameItem(oldname,newname):void
      • changes the name of a array item
      • note - the name is a special attribute of a item, it can't be changed direct!
    • removeItem(name):*
      • removes the item from the array
      • and returns the removed item

    here a example how to parse a array in AS3 in the fastest way: (AS3 code)


    I hope I could clarify some of the krpano internals to help using it

    best regards,
    Klaus

  • Hi Klaus,

    Thanks for the info. That got me one big step further. I noticed though, that the array has 2 empty(?) entries [0] & [1], which are not created anywhere. I generate the array in AS3:

    Code
    plugin_object.createarray("thumb");


    fill it in xml:

    Code
    set(plugin[thumbs:panos].thumb[0].url,1.jpg);
    set(plugin[thumbs:panos].thumb[1].url,2.jpg);
    set(plugin[thumbs:panos].thumb[2].url,3.jpg);
    set(plugin[thumbs:panos].thumb[3].url,4.jpg);


    and read it out in AS3:

    this returns 6 entries??? as follows in the krpano trace:

    DEBUG: TypeError: Error #1009
    DEBUG: TypeError: Error #1009
    DEBUG: 1.jpg
    DEBUG: 2.jpg
    DEBUG: 3.jpg
    DEBUG: 4.jpg

    Any idea where these mysterious entries come from? Any help is greatly appreciated!

    Thanks,
    P

  • You know what's even stranger!? I didn't change the xml file, neither the as3 fire... and it works. Might have been something in the browser cache or so. Thanks. I'll post more if it re-appears *smile*

    P

Participate now!

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