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.

publicitarios360

Intermediate

  • "publicitarios360" started this thread

Posts: 205

Location: Habana, Cuba

Occupation: Architect, Photographer, Programmer.

  • Send private message

1

Saturday, December 9th 2017, 4:51pm

Args ISSUE

Hi, this is simple example to create a layer with a picture (in this case f01.jpg placed in the root)
The layer is created when clicked other layer named "test" that is always visible.

The layer is showed ok, but to click it this layer turn off it AND too turn off the layer test. The correct action was to turn off only the new picture layer, no others layers as "test"

Please, What's wrong???

Greets,

Fernando.

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
<krpano>

<preview type="grid(cube,128,128,512,0xCCCCCC,0xF6F6F6,0x999999);" />

<layer name="test"
type="text"
css="font-size:18px;"
align="top"
html="Show picture"
onclick="creafoto_ventana(f01,f01.jpg);"
/>

<action 
name="creafoto_ventana" 
scope="local"
args="nombre,fichero">
addlayer(get(nombre));
set(layer[get(nombre)].url,get(fichero));
set(layer[get(nombre)].align,center);
set(layer[get(nombre)].onclick,set(layer[get(nombre)].visible,false););
</action>

</krpano>


HTML5/Desktop - Firefox 40.0 WebGL and Flashplayer Win 11.8.800.50 Plugin
krpano 1.19-pr14

spacerywirtualne

Professional

Posts: 919

Location: Poland, Europe

Occupation: krpano developer : virtual tours

  • Send private message

2

Saturday, December 9th 2017, 5:08pm

Try this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<preview type="grid(cube,128,128,512,0xCCCCCC,0xF6F6F6,0x999999);" />

<layer name="test"
type="text"
css="font-size:18px;"
align="top"
html="Show picture"
onclick="creafoto_ventana(f01,f01.jpg);"
/>

<action 
name="creafoto_ventana" 
scope="local"
args="nombre,fichero">
	addlayer(get(nombre));
	set(layer[get(nombre)],
		url=get(fichero),
		align=center,
		onclick=set(layer[get(name)].visible,false);
	);
</action>


Piotr
Your own online, cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube

cms4vr team *thumbsup*

publicitarios360

Intermediate

  • "publicitarios360" started this thread

Posts: 205

Location: Habana, Cuba

Occupation: Architect, Photographer, Programmer.

  • Send private message

3

Saturday, December 9th 2017, 7:13pm

Thanks Piotr:

Your advise is mainly to change:
set(layer[get(nombre)].visible,false); by set(layer[get(name)].visible,false);

Of course, that it works fine, but my example is for testing Argument feature.

What is wrong in the original code?

If you create other layer:
<layer name="test2"
type="text"
css="font-size:18px;"
align="right"
html="Hide layer"
onclick="set(layer[get(nombre)].visible,false);)"
/>

To click this layer ALL LAYER TURN OFF, no only the target.

Note: For this case, change the scope to "global"

Any idea?

Greets,

Fernando

4

Saturday, December 9th 2017, 9:16pm

i think the problem here is how you define the onclick action.
when it is executed, nombre is maybe not set, because it was a local variable
i didnt test this, but i would do:

Source code

1
2
3
4
5
6
7
8
9
<action name="creafoto_ventana" scope="local" args="nombre,fichero">
	addlayer(get(nombre));
	copy(layer[get(nombre)].url, fichero);
	set(layer[get(nombre)].align, center);
	set(layer[get(nombre)].onclick,
		debug(nombre);
		set(layer[get(nombre)].visible,false);
	);
</action>

with this you''ll see if nombre is correctly set there...

if not, you must construct a non dependent onclick action:
set(layer[get(nombre)].onclick, calc('set(layer[' + nombre + '].visible,false);');

ofcourse piotr is right, using name lets you avoid that hoop,
because you set the name to nombre with addlayer(), so
in the onclick event they are always the same.

publicitarios360

Intermediate

  • "publicitarios360" started this thread

Posts: 205

Location: Habana, Cuba

Occupation: Architect, Photographer, Programmer.

  • Send private message

5

Sunday, December 10th 2017, 12:46am

Hi indexofrefraction, thanks for your answer too.

I only are testing the new arguments feature.

I see that isn´t so easy. Your example fail too, the nombre var never get the correct value for onclick action.
To try set(layer[get(nombre)].onclick, calc('set(layer[' + nombre + '].visible,false);'); is too much code for something very simple .

I will comback to old way:

Source code

1
2
3
4
5
6
7
name="creafoto_ventana">
addlayer(%1);
set(layer[%1].url,%2);
set(layer[%1].align,center);
set(layer[%1].ondown,draglayer(););
set(layer[%1].onclick,removelayer(%1));
</action>


Please I would like to see true examples that it shows the best practice of use arguments versus use %
Until now % is good. The new arguments looks good in theory, but I lack to examples o documentation to test.

Thanks to all, for your post. Best regards,

Fernando.

6

Sunday, December 10th 2017, 2:07am

i cant advise that.
it is better to use the local scope whenever you can.
yes its a bit more to think about, but if you do more complex stuff,
then you're happy not to worry about global variables messing up other actions
(ok, in this case you dont use any variable, so it does not matter so much)
as said, using name would have been perfect in this case,
the calc actions was just to explain what is happening.