Question

I'm having difficulties with click event after adding some child :Loader instances in it.

var wr:Sprite=new Sprite();
stage.addChild(wr);         
wr.graphics.drawRect(0,0,stage.width,stage.height);
wr.width=stage.width;
wr.height=stage.height;
wr.addEventListener('click',function():void{
    log('CLICKED!');
});
wr.addChild(el.sprite);

Problem is that click event is only working when i'm clicking on el.sprite, but when i'm clicking anywhere on the stage, it's not working(not triggering click event).

Why would it do that? Haven't i stretched wr layer on the whole stage?

What i'm missing or doesn't understand in flash DisplayObject list mechanics?

I'm trying to position el.sprite(pause button) on the center of wr(pause layer) and apply click event on the whole wr layer(whole stage).

I'm developing video player. :)

Was it helpful?

Solution

drawRect isn't actually drawing anything because you haven't set the fill.

Add this before drawRect:

wr.graphics.beginFill(0xFFFFFF, 0);

That will set the fill to 0 alpha white (if you want it visible, remove the second parameter). Now when you call drawRect it has something to draw with.

OTHER TIPS

The Graphics object in the Flash API is essentially a finite state machine, meaning that you need to (1) tell it to begin, (2) give it one or more sequential commands, and then (3) tell it to stop.

In this case, the key you're missing is the begin and end command. The simplest of which is beginFill() and endFill(). You can see the complete list in the AS3 documentation on Graphics.

beginFill() takes two arguments -- the first being the color of the fill, and the second being the alpha of the fill. So if you want the fill to be invisible, give it whatever color you wish (0 is fine), but also give it an alpha of 0.

Also, as a side note, you don't need to manually set the width and height of the object you named "wr." Once you've drawn the rectangle, its width and height properties will reflect the size of the rectangle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top