• 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.

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

  • Try this:

    Piotr

  • 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

  • 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:

    Code
    <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.

  • 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:

    Code
    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.

  • 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.

Participate now!

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