Home / Topic / Passing command to another page

Passing command to another page

Home Kwiksher Forums Kwik4 Passing command to another page

Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • #86048

    One thing that I have never been able to understand is how to pass a command to a page from an overlay. Any tips on how this is accomplished? For example, if I wanted to use setfillcolor to change the color of an object in in a page from a button in the overlay?

    Yamamoto
    Keymaster
    #86049

    A global variable or dispatching an event to the page will work to interact from the overlay page. I will check the behavior today.

    Yamamoto
    Keymaster
    #86051

    myListener.lua in the page’s external code


    Runtime:addEventListener( “myEvent”, function(event)
    print(“event.text”)
    end)

    myDispatcher.lua in the button of overlay


    Runtime:dispatchEvent({ name=”myEvent”, text=”Changed By dispatchEvent” })

    Alternatively use a global varibale set with Kwik

    myListener.lua in the page’ external code


    Runtime:addEventListener( “enterFrame”, function(event)
    print(_K.myVar)
    end)

    myDispatcher.lua in the button of overlay


    _K.myVar = “Changed From Overlay”

    For instance, in an external code, you can access a displayObject with layer.YOUR_LAYER_NAME

      
       if _K.myVar == "Blue" then
          layer.YOUR_LAYER_NAME:setFillColor(0, 0, 1) -- R, G, B
       end
    

    You can get a value from Overlay to set it to the function.

    #86052

    That is helpful, thank you.

    #86073

    How would I remove this event listener?

    Yamamoto
    Keymaster
    #86075

    OK, the listener was an anonymous function. let’s give it a function name to remove it later

    
    local myListener = function(event)
       print(“event.text”)
    end
    
    -- Remove
    Runtime:addEventListener( “myEvent”, myListener)
    
    -- Add
    Runtime:removeEventListener( “myEvent”, myListener)
    
    #86077

    Thank you. I was having trouble figuring out that one on my own.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.