ondown move hotspot

  • Hi,

    Im trying to create a button which hovers above the hotspot, while pressed it should drag the hotspot. So somehow I need to

    ondown, mousex -> ath.

    Code
    <hotspot name="tiny_bar" keep="true" visible="true" alpha="0.8" url="tinybar_bg.png" enabled="true" handcursor="false" ox="-50" oy="-50" zorder="1000" />
    <plugin name="tiny_bar_move" parent="hotspot[tiny_bar]" keep="true" alpha="1" visible="true" url="move.gif" enabled="true" x="22" y="0" width="16" height="16" align="center" zorder="1001" 
    ondown="
    screentosphere(get(mouse.x),get(mouse.y),tmp_h,tmp_v);
    set(hotspot[tiny_bar].ath,get(tmp_h));
    set(hotspot[tiny_bar].atv,get(tmp_v));" />

    but it jumps all over the place.

    Any idea?

  • Ok that worked, only the ondown event only fires once, so it's not really a "drag". So I binded an onhove to the ondown event. But it still doesnt work

    Is there a way to simulate the flash stopDrag and startDrag within krpano? or javascript would be fine to, I tried to bind an onMousedown event on the hotspot object, but it seems krpano().get doesnt return an object, just a value (string).

    Edited once, last by Zephyr (January 8, 2011 at 1:08 PM).

  • Hi,

    here a simple piece of code for dragging an hotspot:

    Code
    ondown="set(dragging,true); draghotspot();"
    onup="set(dragging,false);"

    and

    Code
    <action name="draghotspot">
      if(dragging, 
    	screentosphere(mouse.x,mouse.y,ath,atv);
    	delayedcall(0,draghotspot());
    	);
    </action>

    a variable - "dragging" - will be set on mouse down, and then the "draghotspot" action will be constantly called to set the ath/atv coordinates from the mouse position as long as that variable is set, and on mouse up this "dragging" variable will be simply set to false to stop that updating,

    best regards,
    Klaus

  • Awesome Klaus! That did the trick! :)

    Curious, why is the delayedcall of 0 seconds necessary? To enforce a "lag" in the loop? Wouldnt the calculations performed in the action not enforce the necessary delay? or is the loopcall asynchronous instead of sequential

  • Hi,

    Flash itself is synchronous, there is no real 'background' processing or so,
    it works sequentially like that:
    executing code -> rendering frame -> executing code -> rendering frame -> ...

    the delayedcall(0, ..) is used to call that code later as soon as possible again (in the next flash frame refresh),
    the normal krpano actions that were called were also executed/processed sequentially all at once in the 'executing code' step,
    and when all code was done, the next frame was rendered,

    without delayedcall that would be an endless loop, it will never leave the 'executing code' step,

    only the blocking actions like wait/lookto/looktohotspot/moveto/zoomto are a special in that way,
    they stop then action execution/processing, do their job and then continue the the actions processing,

    the tween() action is also a special case, then call it will start and then processed every frame to update the value,

    best regards,
    Klaus

  • Yeah plugins would work to. I have made a bar (plugin) with buttons on it (alsoo defined as plugins) when you press and hold the move button, a linked hotspot moves + the bar with the buttons in it.

    instead of translating x/y coordinates to spherical, you could just use the coordinates, but with an offset (because the button is somewhere else then the map)

    <action name="draghotspot">
    if(dragging,
    add(tmp_x, get(mouse.x), 50);
    add(tmp_y, get(mouse.x), 50);
    set(plugin[map].y, tmp_y);
    set(plugin[map].x, tmp_x);
    delayedcall(0,draghotspot());
    );
    </action>

    It takes some time to set up the plugins, and link the children, so you only move the parent map but it works.

  • Zepher this code is not working for me. When i set it to a plugin and click on it the plugin jumps to the bottom right corner. i found the error in the add(tmp_y, get(mouse.Y), 50); the Y was an X fixed that and it still does not work. I want to click in my map move it to another corner and leave it there. Any ideas what is not working?

Participate now!

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