View Full Version : [4.0] Ext.draw.CompositeSprite does not return event object onClick

27 Apr 2011, 2:49 PM
Following code using Ext.draw.CompositeSprite

afterRender: ->
@callParent arguments

first_item = Ext.create 'Ext.draw.CompositeSprite', surface: @drawPanel.surface

rect = Ext.create 'Ext.draw.Sprite',
surface: @drawPanel.surface
type: 'rect'
width: 100
height: 40
fill: '#79BB3F'
radius: 20
x: (200 / 2) + 40
y: 200 / 2 - 20

first_item.add rect
rect.show true

text = Ext.create 'Ext.draw.Sprite',
surface: @drawPanel.surface
type: 'text'
text: 'Organisation'
fill: '#000'
x: (230 / 2) + 40
y: 220 / 2
first_item.add text
text.show true

first_item.on 'click', (sprite, event) ->
console.log arguments
menu = Ext.create 'QM.view.organisation.ContextMenu'
menu.showAt event.getXY()

A few things in the above I notice are:

1) I can't pass first_item.add an object, I need to pass it an instance from a constructor, the code tries to add event handler to it with .on but this only works if you pass a instance.

2) When creating a CompositeSprite, I have to pass the surface to both the composite and each individual sprite.

3) I have to manually make each sprite show, cannot do it with composite.

The biggest issue I have though at the moment is the onClick return values from above return the sprite and an empty object, there is no event object to do .getXY from for example - however if I add the click handler to the individual sprites it works fine. I haven't checked other handlers, but looking at the source code I think the same thing will happen with other mouse events.