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.

1

Wednesday, April 27th 2011, 3:59pm

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:

Source code

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

Source code

1
2
3
4
5
6
7
8
9
10
...
var destVarName:String = "testvar"
var myArray:Array = [11,12,13,14,15,16];

this.plugin_obj.createarray(destVarName);
var kresult:Object = this.krpano.get(destVarName);
for (var i:Number=0; i<result.length; i++) {
	this.krpano.set(destVarName+"["+i+"]", result[i]);
}
...


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

Tuur

Sage

Posts: 3,822

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

3

Wednesday, April 27th 2011, 4:22pm

Thanks for looking. I already found these two, but they don't help me out.

4

Thursday, April 28th 2011, 11:43pm

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

Here's my naive approach again:

Source code

1
2
3
4
5
6
7
8
<action name="sendwallpost">
	createarray(test);
	set(test[item1], "abc");
	set(test[item2], "def");
	trace(test[item1]);
	trace(test[item2]);
	trace(test.count);
</action>


But that results in the following traces:

Source code

1
2
3
def
def
test.count

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

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

5

Friday, April 29th 2011, 1:06am

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:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<krpano version="1.0.8" onstart="showlog();">	

	<preview type="grid(cube,32,32,512,0x000000,0x111111,0x555555);" />

	<events onclick="sendwallpost();" />
	<!--events onclick="action2();" /-->
	
	<action name="sendwallpost">
		createarray(test);
		set(test[item1], "abc");
		set(test[item2], "def");
		trace(test[item1]);
		trace(test[item2]);
		trace(test.count);
	</action>

	<action name="action2">
		createarray(test);
		trace(test.count);
		set(test[item1], "abc");
		set(test[item2], "def");
		trace(test[item1]);
		trace(test[item2]);
		trace(test.count);
		set(test[item1].var, "abc");
		set(test[item2].var, "def");
		trace(test[item1]);
		trace(test[item2]);
		trace(test[item1].var);
		trace(test[item2].var);
		trace(test.count);
	</action>

	<action name="action3">
		trace(test.count);
		set(test[item1].var, "abc");
		set(test[item2].var, "def");
		trace(test[item1]);
		trace(test[item2]);
		trace(test[item1].var);
		trace(test[item2].var);
		trace(test.count);
	</action>

	<style name="buttonstyle"
	   	url="%SWFPATH%/plugins/textfield.swf" children="false"
	   	width="80" height="22"
	   	css="p{color:#000000; font-family:Arial; font-weight:bold; font-size:14; margin-left:5; margin-right:5; text-align:center; }" 
	   	backgroundcolor="0xFFFFFF" roundedge="5" shadow="1" borderwidth="0" glow="4" glowcolor="0xFFFFFF" 
	   	visible="false" 
	   	onover="tween(alpha,0.7,distance(0.3,0.2));" 
	   	onout="tween(alpha,1.0,distance(0.3,0.2));" 
	   	onloaded="set(alpha,0);set(textblur,15);set(blur,15); set(visible,true); tween(alpha,1,0.3); tween(textblur,0,0.3); tween(blur,0,0.3);"
	   	/>	
	
	<plugin name="action1" keep="true" style="buttonstyle"
	    	html="[p]action1[/p]"
	    	align="top" x="-100" y="35"
	    	onclick="sendwallpost();"
	    	/>

	<plugin name="action2" keep="true" style="buttonstyle"
	    	html="[p]action2[/p]"
	    	align="top" x="0" y="35"
	    	onclick="action2();"
	    	/>

	<plugin name="action3" keep="true" style="buttonstyle"
	    	html="[p]action3[/p]"
	    	align="top" x="+100" y="35"
	    	onclick="action3();"
	    	/>

</krpano>

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:

Source code

1
2
3
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 ;-) ...

SAlut.

6

Friday, April 29th 2011, 9:15am

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

Source code

1
2
3
4
5
6
7
8
9
10
...
var destVarName:String = "testvar"
var myArray:Array = [11,12,13,14,15,16];

this.plugin_obj.createarray(destVarName);
var kresult:Object = this.krpano.get(destVarName);
for (var i:Number=0; i<result.length; i++) {
	this.krpano.set(destVarName+"["+i+"].value", result[i]);
}
...

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

This post has been edited 1 times, last edit by "ahoeben" (Apr 29th 2011, 9:29am)


7

Thursday, May 5th 2011, 4:36pm

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,
Klaus

8

Thursday, May 5th 2011, 7:52pm

Aha! I see...
And the object.count "property" is basically just another variable, not an actual property?
I might have to write a plugin for using proper arrays for storing data then...

9

Wednesday, May 11th 2011, 11:46am

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,

Quoted

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,
Klaus

10

Wednesday, May 11th 2011, 11:04pm

Thanks for clarifying, I misunderstood your last reply.