PDA

View Full Version : Remove mouse events



Ricky55
December 21st, 2009, 01:09 PM
Hi

I am using a array to provide my movieclips with mousevents.

These movieclips are loading in external swfs, underneath each loaded swf I have a black rectangle that covers the content underneath.

When one of the external swf's is being viewed and the black rectangle is visible how can I remove my mouse events until the black box as disappeared? So when the user is viewing a loaded in swf I don't want the movieclips underneath to be moving about.

You can see the file here

http://www.qwerty-design.co.uk/Clients/Hygenic/

Only the first button is working properly.

My code



//Black Cover used for loaded movies
var blackCover:Sprite = new Sprite();
blackCover.graphics.beginFill(0x000000);
blackCover.graphics.drawRect(12, 12, 954, 564);
blackCover.alpha = .6;

//Array for mouse events and button movement
var buttonArray:Array =
[
carWash,
foodDrink,
prepAreas,
hoardings,
retailers,
retailOne,
retailTwo,
pools,
diy,
miscellaneous
];

for (var i:uint=0; i<buttonArray.length; i++)
{
buttonArray[i].buttonMode=true;
buttonArray[i].addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
buttonArray[i].ox = buttonArray[i].x;
buttonArray[i].oy = buttonArray[i].y;
buttonArray[i].tx = buttonArray[i].ox;
buttonArray[i].ty = buttonArray[i].oy;
buttonArray[i].addEventListener(MouseEvent.ROLL_OVER, onOver);
}

//Loads in the external swfs and other associated elements
function onClick (event:MouseEvent):void
{
btnClick.play();
addChild(blackCover);
addChild(preLoad);
currentURL = urlList[buttonArray.indexOf(event.target)];
trace(currentURL);
var theURL:URLRequest = new URLRequest(currentURL);
loader.load(theURL);
addChild(loader);
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, animatePreLoader);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, movieLoaded);
function animatePreLoader(event:ProgressEvent):void
{
var bytestotal = event.bytesTotal;
var bytesloaded = event.bytesLoaded;
var percentVar = Math.round(bytesloaded * 100 /bytestotal );
preLoad.gotoAndStop (percentVar);
}
}

e_owen
December 21st, 2009, 07:51 PM
in the onClick function you can loop through the buttonArray and remove the ROLL_OVER event listener or then when one of the loaded_swfs is closed it could dispatch an event to the class below which could turn the ROLL_OVER back on when.

At the moment it seems strange though because the blackCover is 'blocking' a mouse click on those buttons but not the ROLL_OVER - which it should.

Make sure you have


blackCover.mouseEnabled = true;
blackCover.mouseChildren = true;

Ricky55
December 22nd, 2009, 06:23 AM
Thanks man.

It was actually a different event that was causing the movement, all the on over was doing was moving the clips to the top.

Anyway you put me on the right track.

Sorted now!

Thanks

Ricky55
December 22nd, 2009, 06:24 AM
by the way when you remove and event listener do you always have to specify the full details for example if I have:

loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, movieLoaded);

Can this be removed with

removeEventListener(Event.COMPLETE, movieLoaded);

or do I need:

loader.contentLoaderInfo.removeEventListener(Event .COMPLETE, movieLoaded);

e_owen
December 22nd, 2009, 05:47 PM
loader.contentLoaderInfo.removeEventListener(Event .COMPLETE, movieLoaded);

add/removeEventListener is a method so you need to target it to the object in question. how you reference the target object is up to you - it could be event.target or btnArray[2] - whatever you require. hope that makes sense.