1
votes

I need to place a transparent sprite over another sprite. The overlaying sprite will acept some mouse events. When a user move mouse over upper sprite a curve will be drawn. After it'll be processed it will be drawn on the base sprite (and erased on upper).

The idea I have now is to place the sprite, draw a rectange of size equal to sizes of sprite and set alpha to 0.

The question is a bit dump: maybe the proposed solution is not the best. Is there a better way to set width and height (as far a I understand Sprite.width = w; will not help)?

Thank you in advance!

1
Why can't you set this mouse eventos on the sprite itself?Ricardo Souza
Well, that's not possible for me. I've updated the question: When a user move mouse over upper sprite a curve will be drawn. After it'll be processed it will be drawn on the base sprite (and erased on upper).Eugeny89
What you are doing is correct. You can't set the width or height of a Sprite. It takes the dimension of the bounding rectangle of its content.Diode

1 Answers

4
votes

You can't set dimensions directly, while you can draw over that Sprite. So you can do like this:

graphics.beginFill(0,0); // zero alpha fill
graphics.lineStyle(0,0,0); // invisible lines
graphics.drawRect(0,0,width,height);
graphics.endFill();

This way your Sprite can have its alpha remaining at 1, to not hide anything that's its child. Then, whatever curve you would decide to draw in that Sprite, you can draw within a child Shape object, via graphics.moveTo and graphics.lineTo.

UPDATE: According to comments below, setting alpha to 0 won't work with newer Flash player versions, so alpha should be set to a nonzero amount for the events to register on the overlapping sprite.

graphics.beginFill(0x808080,0.01); // almost zero alpha fill