views:

285

answers:

2

Hi, i am trying to implement the following control on a movieclip object. When the mouse pointer is over the object and if the left mouse button is clicked and stays clicked then a mask that overlaps the movieclip object is starting to disappear. I tried the MouseEvent.DOWN, etc but i did not succeed to implement this functionality. Probably i miss something. Can i achieve this through standard mouse events types or do i have to implement it another way? Also is it possible instead to fade out the mask by reducing the alpha attribute, to actually make dissappear the pixel(s) that under the mouse pointer ?

A: 

MouseEvent.MOUSE_DOWN/Mouse.MOUSE_UP are indeed the events to use so there most be a problem in your code.

It often happens this event doesn't get triggered because of objects overlapping and I suspect in this case it might be the mask. If this is the case you can simply disabling mouseEvents on the obstructive displayObjects with mouseEnabled = false.

Example :

var background:Sprite,
    foreground:Sprite; // Note: could be MovieClips of course !

// adds a sprite with a pink circle
addChild(background = new Sprite());
background.graphics.beginFill(0xff0099);
background.graphics.drawEllipse(0,0,100,100);

// adds a sprite containing a black box and adds it on top of the circle
addChild(foreground = new Sprite());
foreground.graphics.beginFill(0x000000);
foreground.graphics.drawRect(0,0,100,100);

background.buttonMode = true; // not necessary, just adds the handcursor on rollover to let you debug easier.
foreground.mouseEnabled = false; // the foreground is not clickable anymore, which makes the background clickable


background.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);

function onMouseUp(e:Event):void
{
    foreground.visible = 0; // I let you do the animation here ; )
}

A few quick hints regarding the pixel under the cursor :

You can do it with a Bitmap object. The pixel coordinates can be retrieved with mouseX, mouseY (note that bitmap objects don't dispatch mouse events so you need to add it to a sprite to use as a wrapper). You can retrieve the pixels actual color/alpha by getPixel32 and modify it by setPixel32.

If you are having troubles I suggest you open a separate question for that.

Hope it helps, T.

Theo.T
thanks Theo actually i achieve the effect i wanted by using correctly the MOUSE_DOWN, MOUSE_UP, AND MOUSE_MOVE events. Actually i registered two separate events for each MOUSE_DOWN, MOUSE_UP. In MOUSE_UP i include a object.removeEventListener(MOUSE_MOVE, mousedown) and in MOUSE_DOWN i include a object.addEventListener(MOUSE_MOVE, mousedown) plus the actions i want to triger.
Ponty
A: 

Thanks for your reply. Actually i tried the code but it doesn't implement the desired result. The control that i want to achieve is described better here: I have two overlapped Sprites(or MovieClips) identical in size. When i put the mouse over the foreground image i want to trigger an event when i press the left button down and keep the event triggering as long as the mouse is kept down. The basic idea is to reveal the parts of the background image that is under the mouse pointer.So while the left mouse button is kept clicked and the mouse pointer traverses the foreground image the corresponding parts of background image are revealed.

Ponty
I tried to comment Theo's answer but the text was longer, so this post is an answer to Theo's answer !
Ponty