You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Zephyr

Professional

  • "Zephyr" started this thread

Posts: 968

Location: Netherlands

Occupation: Web developer

  • Send private message

1

Tuesday, June 2nd 2009, 11:43am

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?

Source code

1
2
3
4
<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:

Source code

1
2
3
4
5
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?
3d childrens game using krpano Game
Minify your xml with my krpano XML Compressor
Krpano XML Parsing Error Checklist
Available for hire (krpano xml, javascript, actionscript, flash, php and ipad plugins).

2

Tuesday, June 2nd 2009, 1:59pm

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:

Source code

1
2
3
4
<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():

Source code

1
2
3
4
5
6
7
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 )

Source code

1
2
3
4
5
6
7
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

Zephyr

Professional

  • "Zephyr" started this thread

Posts: 968

Location: Netherlands

Occupation: Web developer

  • Send private message

3

Tuesday, June 2nd 2009, 3:24pm

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.

Source code

1
if(plugin[advancedcontrols].toggled EQ 1, include some xml);
3d childrens game using krpano Game
Minify your xml with my krpano XML Compressor
Krpano XML Parsing Error Checklist
Available for hire (krpano xml, javascript, actionscript, flash, php and ipad plugins).

4

Monday, June 8th 2009, 4:02pm

Hi,

no, the <include> tags were parsed and resolved while loading the xml itself,

best regards,
Klaus