LOGIN Don't have an account yet?   Register

Forgot password?
 
01Jun2009

Release Outside in AS3 – Firefox 3 on mac trick


As you probably heard in AS3 to treat the “release_outside” event it’s a little bit tricky.
But AS3 comes with solutions for everything even for “stage_leave” event. In AS2 you couldn’t do that.
Now you can do that by treating the “Event.MOUSE_LEAVE” event.
To do that you need to use event listeners also on stage.

This is how we do it step by step:

1. Use a global variable to know every time what was the last pressed object.

// HANDLERS VARS
var currPressedObject : *;

2. Secondly add the event listeners on the object that the user will interact with.

mcTest.buttonMode = true;
mcTest.addEventListener(MouseEvent.MOUSE_DOWN, pressHandler);
mcTest.addEventListener(MouseEvent.MOUSE_UP, releaseHandler);

3. Inside the “presshandler” function you need to update every time the “currPressedObject” variable and simulate the treating of the “release_outside” event:

// set the new pressed object
currPressedObject = mc;

// add the release event on stage to simulate releaseOutside listener
stage.addEventListener(MouseEvent.MOUSE_UP, releaseOutsideHandler);

We discovered that in Firefox 3 on MAC there is a problem with treating the “release_outside_scene” event that should be the same as “release_outside”. The code above is not enough.
To fix the problem you will have to add the “releaseOutsideHandler” also for the “Event.MOUSE_LEAVE” inside the “presshandler” function:

stage.addEventListener(Event.MOUSE_LEAVE, releaseOutsideHandler);

4. Inside the “releaseOutsideHandler” write the code for those objects that need to have this event treated as below:

function releaseOutsideHandler(e : Event) : void
{
// remove stage event listeners
stage.removeEventListener(MouseEvent.MOUSE_UP, releaseOutsideHandler);
stage.removeEventListener(Event.MOUSE_LEAVE, releaseOutsideHandler);

// here release outside code only for the items that need "release outside" listener
if(currPressedObject == mcTest)
{
ttrace("OUTSIDE");
mcTest.stopDrag();
currPressedObject = null;
}

// if(currPressedObject == mcOtherClip) {}
}

5. Inside the “releaseHandler” write the code that will be executed only if the user releases the mouse on the same object where they pressed:

function releaseHandler(event : MouseEvent) : void
{
var mc : MovieClip = MovieClip(event.currentTarget);

// test if the releasse event comes from the same item that was pressed
if(mc == currPressedObject)
{
// for every item write the code here:
if(mc == mcTest)
{
mcTest.stopDrag();
currPressedObject = null;
}
// if(mc == mcOtherClip) {}
}
}

This is our final code that we used in our experience that should work on any browser and any kind of interaction between your user and your flash product.
You can download the full flash and html sample from here .
I hope it will heal your headache in just a few seconds on solving issues with the interaction.
Please let us know if it worked for you and if you could add anything else.

This post has 3 comments | Post your comment

Nisse

November 11, 2009 at 7:36 am

Hi! This made my day. I have had very big problems with this.

For the record:
I get the mouseLeave event when the user releases the mouse outside the stage (and the browser window as well) and not, as one might would expect, when the mouse leaves the stage.

Works great in FF3 on MAC

Reply

bobocel

November 14, 2009 at 12:20 am

Glad it works! A good example is our 360 Viewer. Try to release the mouse outside the stage and browser if you want to, from the controller. The file is free, so you can check the code if you want to. ;)

Reply

Anthony J

March 8, 2010 at 12:11 pm

Hey. I’m getting errors when I try to build with the code above, and the fla file I downloaded won’t open for me. Unexpected file format. Probably CS4?. Though the swf works perfectly! Can you post or email me the complete src as text?

Reply

Leave a Reply

blog entries RSS Feedproducts RSS Feed

Categories

Popular Files

  • Compact Flash Mp3 Player
  • Horizontal Image Slide on Mouse Move
  • Accordion Menu with Images from XML
  • Accordion Banner Rotator
  • Continuous Image Slider
  • Mp3 Player with Playlist
  • Flash Ken Burns Effect Slideshow
  • Accordion Gallery
  • Horizontal Scroller Slideshow
  • Fade In Fade Out Slideshow With Navigation
  • Simple AS3 Flash Video Player
  • Zoom Gallery

Download the plugin above
Read more about Flabell WordPress plugin

Archives

Search the blog