Soviut
Soviut

Reputation: 91525

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?

Upvotes: 0

Views: 356

Answers (2)

Cay
Cay

Reputation: 3794

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

Upvotes: 2

Tyler Egeto
Tyler Egeto

Reputation: 5495

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.

Upvotes: 2

Related Questions