understanding asyncloop

  • hi everyone,
    i have a question to asyncloop, and how it works...

    in vtourskin it is basically implemented like this:

    Code
    <style name="skin_tooltips"
    onover.mouse="set(layer[skin_tooltip].visible, true);
        asyncloop(hovering, copy(layer[skin_tooltip].x,mouse.stagex); copy(layer[skin_tooltip].y,mouse.stagey););"
    onout.mouse="set(layer[skin_tooltip].visible,false);"
    />

    the variable "hovering" will make the loop running or not when true or false, this is clear, but...
    isnt every onover event creating a NEW asyncloop,
    so that after some time using the gui, multiple loops do the same thing?

    or is there an internal identification and a second asyncloop call doesnt create a new loop?

    best, index

  • isnt every onover event creating a NEW asyncloop,

    no - why?


    The example itself work that way:

    1. when hovering an element, its hovering attribute will be set to true and its onover event be called
    2. the asyncloop() call will be started and kept executing every frame as long as the given condition (hovering==true) will be true - that means the given condition will be checked every frame again if its still true
    3. when the mouse moves out of the element, its hovering attribute will be set to false and the onout event be called
    4. now hovering is false and now also the asyncloop() automatically ends

    Code snippets like:

    Code
    onover="initcode; asyncloop(hovering, loopcode, donecode*);"

    or

    Code
    ondown="initcode; asyncloop(pressed, loopcode, donecode*);"

    can be quite powerful - they are allowing doing many things with just one event call.

  • so code after the asyncloop() call is not executed until the asyncloop stops?

    Again - no ;-).
    Code after asyncloop() will be directly executed:

    1. first the looping condition will be checked,
    2. when true, the 'loopactions' will be executed (otherwise the 'doneactions' - the optional third parameter)
    3. then the actions after the asyncloop call will be executed
    4. then in the next frame, the asyncloop condition will be checked again and if still true, the 'loopactions' code be executed again - and if the condition is false, then the 'doneaction' will be executed
  • darn, ok :)

    but thats how i thought it was first... you basically start a thread with it.
    but to do so you must have an internal id, to avoid multiple threads with the same asyncloop, not?
    if i start an asyncloop in onover for example, the same asyncloop call is called a lot of times,
    an we dont have to check if the loop s already running, that works all internal.

    anyway thanks for clarifying..
    and sorry for bothering you with these kind of "how does it work" questions :)

    index

  • you basically start a thread with it.

    No, there is no multithreading, it's all sequential, it's like normal Javascript or Actionscript processing (on which krpano is based on).

    A typical 'frame loop' looks roughly like this:

    1. input processing
    2. actions processing
    3. rendering
    4. repeat on 1.

    but to do so you must have an internal id, to avoid multiple threads with the same asyncloop, not?

    Yes, internally each asyncloop has it own internal id/reference.
    You can use as many asyncloop calls you want, they will not 'use the same asyncloop' (whatever that means ;-)).

    if i start an asyncloop in onover for example, the same asyncloop call is called a lot of times,

    It will be called once the onover event and then in all following frames as long as the condition is true.

    and sorry for bothering you with these kind of "how does it work" questions :)

    No problem of course! *wink*
    Better one question more instead of assuming something wrong.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!