Difference between revisions of "Event"

From GiderosMobile
Line 16: Line 16:
 
'''Mouse down event example'''<br/>
 
'''Mouse down event example'''<br/>
 
<source lang="lua">function onMouseDown(event)
 
<source lang="lua">function onMouseDown(event)
print(event.x, event.y)
+
  print(event.x, event.y)
 
end
 
end
 +
 
mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)</source>
 
mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)</source>
 
'''User created event'''<br/>
 
'''User created event'''<br/>
<source lang="lua">local event = Event.new(&quot;myevent&quot;)
+
<source lang="lua">local event = Event.new("myevent")
event.data1 = &quot;12345&quot;
+
event.data1 = "12345"
event.data2 = &quot;abcde&quot;
+
event.data2 = "abcde"
 
mydispatcher:dispatchEvent(event)</source>
 
mydispatcher:dispatchEvent(event)</source>
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 +
 
=== <translate>Methods</translate> ===
 
=== <translate>Methods</translate> ===
 
[[Special:MyLanguage/Event.new|Event.new]] ''<translate>creates a new Event object</translate>''<br/><!-- GIDEROSMTD:Event.new(type) creates a new Event object -->
 
[[Special:MyLanguage/Event.new|Event.new]] ''<translate>creates a new Event object</translate>''<br/><!-- GIDEROSMTD:Event.new(type) creates a new Event object -->

Revision as of 11:31, 1 November 2018


Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6
Inherits from: Object

Description


The objects of Event class contains information about an event that has occurred. Event objects
are passed to event listeners when an event occurs.

Usually event objects contains specific additional information about the event that has occured. For example,
when an Event.MOUSE_DOWN event occurs, x and y fields contain the coordinates.
Users can create their own events and dispatch through the event mechanism.

Examples

Mouse down event example

function onMouseDown(event)
  print(event.x, event.y)
end

mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)

User created event

local event = Event.new("myevent")
event.data1 = "12345"
event.data2 = "abcde"
mydispatcher:dispatchEvent(event)

Methods

Event.new creates a new Event object
Event:getTarget returns the element on which the event listener was registered
Event:getType returns the type of Event
Event:stopPropagation stops the propagation of the current event in the scene tree hierarchy

Events

Constants