Search code examples
flashactionscript-3dimensionsdisplayobject

Workarounds for setting the size of an empty display object?


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?


Solution

  • 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.