Possible to add objects in plugin?

  • Hi,

    I created a plugin that loads an external xml to build up a menu. To make things more simple, I was wondering if I could add the objects in the external xml in the plugin?

    Code
    <plugin keep="true" alpha="1" customattribute="1" url="plugin.swf">
    <object attribute="1" />
    <object attribute="2" />
    </plugin>

    and from the flashfile I could loop it like:

    Code
    plugin_object = krpano.get(plugin_path);
    for(var i:int = 0; i < plugin_object.object.length(); i++)
    {
        trace(plugin_object.object[i].@attribute);
    }

    Is this possible?

  • Hi,

    yes, that's possible

    but the sub objects must have a "name" attribute for identification,
    and the name must begin with an alphabetic character,
    then an internal array for these objects is created,

    e.g.
    xml:

    Code
    <plugin keep="true" alpha="1" customattribute="1" url="plugin.swf">
    <object name="n1" />
    <object name="n2" />
    </plugin>


    the items of this array can be accessed with the krpano.get() function,
    e.g.:

    as3 - get():

    Code
    var plugin_object:Object = krpano.get(plugin_path);
    var cnt:int = krpano.get("plugin_path + ".object.count");
    for(var i:int = 0; i < cnt; i++)
    {
       var object:Object = krpano.get(plugin_path + ".object[" + i + "]");
       trace(object.name);
    }


    or direct via direct array access (better and faster )

    Code
    var plugin_object:Object = krpano.get(plugin_path);
    var objectarray:Array = plugin_object.object.getArray();
    for(var i:int = 0; i < objectarray.length; i++)
    {
       var object:Object = objectarray[i];
       trace(object.name);
    }


    these internal arrays have these interface functions for as3:

    • count - returns the number of items
    • getItem(index) - returns the object at the given index
    • getArray() - returns a ref to a normal AS3 "Array" which contains all objects


    best regards,
    Klaus

  • Thanks Klaus!

    that did the trick. 1 less xml to lad ;p Another question. Is it possible to <include> files based on a if statement? I want to include certain xml if some attributes been set to 1.

    Code
    if(plugin[advancedcontrols].toggled EQ 1, include some xml);

Participate now!

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