Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Events vs Dispatching Events — Gideros Forum

Events vs Dispatching Events

OZAppsOZApps Guru
edited August 2012 in General questions
Here's the sample code that I tried.
 -- Sample code to test this issue
local function onMouseUp(event)
  for i,j in pairs(event) do
    print(i,j)
  end 
end 
 
stage:addEventListener(Event.MOUSE_UP, onMouseUp)
Now it tells me that one of the members of the event is "type" and has the value of "mouseUp"

I tried to dispatch a mouseUp event as
 local evt = Event.new("mouseUp")  -- Even tried it as Event.new(Event.MOUSE_UP)
 for i,j in pairs(evt) do
  print(i,j)
 end 
 -- There is no "type", instead there is a "_type"
 -- so, tried to manually fix that too
 
 evt.type = "mouseUp"
 stage:dispatchEvent(evt)
 
 -- This does not work. Any ideas why?
twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited August 2012
    Event.MOUSE_UP is a built in event. I doubt you can dispatch it.

    In your case something like this would work:
     -- Sample code to test this issue
    local function onMouseUp(event)
       print("mouseUp")
    end 
     
    stage:addEventListener("mouseUp", onMouseUp)
     
     local evt = Event.new("mouseUp")
     stage:dispatchEvent(evt)
  • Event.MOUSE_UP is a built in event. I doubt you can dispatch it.
    @ar2rsawseen, A slight correction Event.MOUSE_UP is just a string "mouseUp"

    For some reason the code
     -- Sample code to test this issue
    local function onMouseUp(event)
       print("mouseUp")
    end 
     
    stage:addEventListener(Event.MOUSE_UP, onMouseUp)
     
     local evt = Event.new(Event.MOUSE_UP)
     stage:dispatchEvent(evt)
    works, but when I am trying to dispatch it with the same, it doesn't. Maybe @Atilim could shed some light on this.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @DOH!! How silly of me, it works just as I expected it, the code I posted will work, the problem was that the handler was set on another object but triggered on the stage :(
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
Sign In or Register to comment.