[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

sample[LuaStudio] Sprite


SwikiCodeRobot @> 675

Sprite example


Lua code

self cancelfileIn!
-- Sprite.lua

Sprite = Lib.Media.Display.Sprite
stage = Lib.Media.Display.stage

sprite = Sprite.new()
sprite.name = "Sprite 1"
sprite.graphics.lineStyle(2, 0x00FF00, 1.0, false, nil, nil, nil, 3)
sprite.graphics.beginFill(0xFFFF00, 1.0)
sprite.graphics.drawRect(0,0, 200, 100)
sprite.graphics.endFill()
sprite.buttonMode = true
stage.addChild(sprite)

sprite.x = 10
sprite.y = 10

sprite.addEventListener(Lib.Media.Events.MouseEvent.CLICK, 
function(e)
	print(e.target.name)
end, false, 0, false)


Uploaded Image: alert.gif Note

The name "self" is NOT bound to the listener block. It is a native lua function called as function and NOT as OO call, so the "self" binding is missing.
If you use "self" inside the block it can/will crash the hosting app!