Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

mouseEnabled

This is a discussion on mouseEnabled within the Tutorials forums, part of the Flash English category; Hi ! Did it happen to you to assign a mouse event to a MovieClip (such as MouseEvent.MOUSE_DOWN) and realise ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 26-10-08, 05:26
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
mouseEnabled

Hi !


Did it happen to you to assign a mouse event to a MovieClip (such as MouseEvent.MOUSE_DOWN) and realise that it does not comport itself as expected?

It acts as if no event was associated to it?

Certainly, you have another MovieClip above it which blocks the mouse event.


If you have encountered this problem and you could not find the answer, I have the solution for you.


The trick is in the property mouseEnabled of the InteractiveObject Class (also available from the MovieClip class being a subclass of InteractiveObject).



Let us say that I have a MovieClip named ‘clip_mc’ and on a higher level, I have another MovieClip with alpha 50 that covers clip_mc.

In this case, all the events associated to clip_mc are cancelled by the MovieClip on top of it.

To resolve this problem, we can simply add to the top MovieClip .mouseEnabled=false;


Let us take a look at a concrete example…


I create a MovieClip, I assign to it the instance name ‘clip_mc’ and I assign to it the event MOUSE_DOWN so that each time it is clicked a text field returns ‘ok’:


Code:
clip_mc.mouseChildren=false;
clip_mc.buttonMode=true;
clip_mc.addEventListener(MouseEvent.MOUSE_DOWN,go);

function go(evt:MouseEvent):void
{
	debug_txt.appendText('ok'+'\n');
}








Nothing strange. Everything works as it should and when I click, the text field acts as it should as the event is intercepted.


Next, I add the second MovieClip with an instance name ‘over_mc’ on a higher level then clip_mc, keeping the same event associated to clip_mc (the same code)









There it is that clip_mc does not intercept anymore the event MOUSE_DOWN. In fact, if I click, nothing happens…even the hand mouse has disappeared.

This is due to ‘over_mc’ which has by default a property mouseEnabled set to true and hides the mouse event associated to clip_mc.


To resolve the problem, we will need to impost the mouseEnabled to false for over_mc, the following way:


Code:
over_mc.mouseEnabled=false;
clip_mc.mouseChildren=false;
clip_mc.buttonMode=true;
clip_mc.addEventListener(MouseEvent.MOUSE_DOWN,go);

function go(evt:MouseEvent):void
{
	debug_txt.appendText('ok'+'\n');
}








Now, if I click on clip_mc everything is back as it should be.


Stay tuned !

__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Tags
events, mouseEnabled

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
mouseEnabled di Flash CS3 - trucco del giorno Flep Articoli e tutorials 2 16-01-08 07:30


All times are GMT. The time now is 14:28.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap