views:

66

answers:

2

I want to create an invisible drawing surface that sits over top of an image. This drawing surface would be in charge of taking mouse input and passing the coordinates along to a sprite that sits on the layer between the drawing surface and the image. The drawing surface is an empty Sprite.

According to the docs, a display object that has nothing inside it cannot have its width or height set. That is, it will always be zero.

Is there any way around this? What is the best practice?

+2  A: 

You can work with the drawing api to draw shapes with extremely low alpha values, this will give you the values without being visible to the eye.

BUT

Perhaps a better solution would be to register your mouse listeners on the stage from within the drawing surface sprite, and have it handle the mouse events on it's own. I don't know enough about what you are trying to do, but if possible, it would be a cleaner / simpler solution.

Even if you can't put the listeners in the drawing surface sprite, you should be able to add them to the stage from where ever you are working, rather than using an extra object.

Tyler Egeto
oops, you beat me by 10 seconds :P
Cay
I need local coordinates. The drawing surface is effectively acting as a boundary so the user can only draw in a specific location above the image.
Soviut
+2  A: 

If you only need the limits for your drawing, I think the easiest solution would be listening for the stage mouse events, and programaticaly limit your drawing... If you still think you need that transparent sprite, you can draw a transparent rectangle (beginFill(0, 0)) or create a transparent bitmap (new BitmapData(width,height,true,0)). Not sure which would be the "best practice"....

Cay