views:

52

answers:

3

I am creating a component that will be a large plus or a large minus. I don't want to use a bitmap because even I can draw this using the Graphics class, but the component must be clickable (the Shape class is not).

It will be part of an item renderer, so I want it to be as light-weight as possible. UIComponent does not seem to sent CLICK messages.

Thanks for any ideas

+1  A: 

If you look here: UIComponent Docs

You will see that UIComponent has InteractiveObject in its inheritance path. InteractiveObject is the class that adds mouse event functionality.

sberry2A
+2  A: 

I would suggest creating a Sprite object and drawing the minus and plus arrows to its graphics object. You'll then have to addEventListener(MouseEvent.CLICK, someFunction); in its constructor or wherever else you'll need it.

You may also want to set cacheAsBitmap to true at that point, so that it's not redrawn every frame.


EDIT: Per @jeremynealbrown you have to use the SpriteAsset class if you are working in Flex, apparently. Very similar, but another 2 levels of abstraction are added.

Jeremy White
Sprite is the highest class that you can access both the graphics object and the MouseEvent.CLICK event.
Jeremy White
What about MovieClips?
Tyler Egeto
A Sprite is essentially the same thing as a MovieClip, but without the timeline. A Sprite is higher in the heirarchy than a MovieClip, so it will be more lightweight.
Jeremy White
MovieClip extends Sprite :)
Tyler Egeto
I guess it's how you look at it, higher-lower
Tyler Egeto
True, I generally look at the base class as being at the top and everything else comes down from it. Not sure why...
Jeremy White
lol and I think of it the other way around!
Tyler Egeto
Neither will work with the Flex framework, you will need to use SpriteAsset or MovieClipAsset.
jeremynealbrown
+1  A: 

UIComponent will actually dispatch click events. However, if there is no content drawn to the graphics, the UIComponent will have no area that can be clicked. If the plus or minus icon you draw is too small to reliably catch mouse activities, then draw a fully-transparent rectangle to increase the hit area.

joshtynjala
Exactly what I was going to reply :)
Sophistifunk