PDA

View Full Version : onReleaseOutside...


walnutfish
07-20-2006, 04:49 PM
Ok... the event handler coding for most of the removed "on" events is straight forward enough. However, onDragOver - onDragOut - and onReleaseOutside are not so simple. The migration guide states: Replaced in the new event model by a mouseOver/Out/Up event after a call to flash.display.InteractiveObject.setCapture().

Documentation on this setCapture method seems rather sparse, and no examples are given for its uses. Someone who understands this, please help.

csdstudio
07-20-2006, 08:27 PM
I had it all figured out until I discovered that setCapture isn't a method of InteractiveObject or any other class, go figure. Not implemented yet perhaps?

senocular
07-20-2006, 09:02 PM
you have to use a combination of interactiveObject.press and stage.mouseUp (using capture). setCapture has been removed - this happened in Beta 3, but not updated in the docs (yet).

csdstudio
07-20-2006, 09:08 PM
you have to use a combination of interactiveObject.press and stage.mouseUp (using capture). setCapture has been removed - this happened in Beta 3, but not updated in the docs (yet).

Something like this, may not be the most efficient way though :p


import flash.events.*;
var pressedMe:Boolean=false;
object1.addEventListener(MouseEvent.MOUSE_OVER,mou seOverHandler);
object1.addEventListener(MouseEvent.MOUSE_OUT,mous eOutHandler);
object1.addEventListener(MouseEvent.MOUSE_DOWN,mou seDownHandler);
object1.addEventListener(MouseEvent.MOUSE_UP,mouse UpHandler);
function mouseOverHandler(event:MouseEvent){
if(event.buttonDown){
object1.stage.removeEventListener(MouseEvent.MOUSE _UP,mouseReleaseOutSideHandler);
trace("MOUSE_DRAGOVER");
}else{
trace("MOUSE_OVER");
}
}
function mouseOutHandler(event:MouseEvent){
if(event.buttonDown && pressedMe){
trace("MOUSE_DRAGOUT");
object1.stage.addEventListener(MouseEvent.MOUSE_UP ,mouseReleaseOutSideHandler);
}else{
trace("MOUSE_OUT");
}
}
function mouseDownHandler(event:MouseEvent){
trace("MOUSE_DOWN");
pressedMe=true;
}
function mouseUpHandler(event:MouseEvent){
trace("MOUSE_UP");
pressedMe=false;
}
function mouseReleaseOutSideHandler(event:MouseEvent){
trace("MOUSE_RELEASEOUTSIDE");
object1.stage.removeEventListener(MouseEvent.MOUSE _UP,mouseReleaseOutSideHandler);
pressedMe=false;
}


Assuming this code is on frame one and there is a movieclip named object1.

Oh it's so nice not having to use Delegate.

senocular
07-20-2006, 09:48 PM
You should use bubbling for your stage event handlers in case there are other instances that stop propagation
object1.stage.addEventListener( MouseEvent.MOUSE_UP,mouseReleaseOutSideHandler, true );
object1.stage.removeEventListener( MouseEvent.MOUSE_UP,mouseReleaseOutSideHandler, true );

csdstudio
07-21-2006, 05:35 PM
senocular, do you have anything written up that explains the new event modeling structure? Specifically bubbling, phases, etc. I'm a bit confused in that matter.

Thanks!

senocular
07-21-2006, 05:41 PM
Not specifically with AS3... though that would probably be a good idea.

The closest I have now is:
http://www.senocular.com/flash/tutorials/buttoncapturing/

But that mostly covers how AVM1 doesn't support it.

csdstudio
07-21-2006, 05:46 PM
Not specifically with AS3... though that would probably be a good idea.

The closest I have now is:
http://www.senocular.com/flash/tutorials/buttoncapturing/

But that mostly covers how AVM1 doesn't support it.

Ha! I just figured that out. I think I'm on to what your saying. AVM2 supports propagation of events, so by capturing the event you prevent the event from propagating?

I just did this quick to test it and they both fire in AVM2:


box_mc.addEventListener("mouseDown",handler1);
function handler1(event){
trace("box_mc pressed");
}
box_mc.plate_mc.addEventListener("mouseDown",handler2);
function handler2(event){
trace("plate_mc pressed");
}

csdstudio
07-21-2006, 05:54 PM
Uh, nope. Just proved my own theory wrong.

By putting capture on the inner movieclip, then that one never fires:

box_mc.addEventListener("mouseDown",handler1);
function handler1(event){
trace("box_mc pressed");
}
box_mc.plate_mc.addEventListener("mouseDown",handler2,true);
function handler2(event){
trace("plate_mc pressed");
}
//only box_mc pressed is traced


But when I capture the other, both events fire yet in reverse order:

box_mc.addEventListener("mouseDown",handler1,true);
function handler1(event){
trace("box_mc pressed");
}
box_mc.plate_mc.addEventListener("mouseDown",handler2);
function handler2(event){
trace("plate_mc pressed");
}
//box_mc pressed
//plate_mc pressed


I guess I'm more confused now than before.

senocular
07-21-2006, 05:55 PM
right. So when you click on something, that event starts at the object you clicked and then gets sent to each parent. Click on c_mc in a_mc.b_mc (a_mc.b_mc.c_mc) c_mc will get the event first, then b_mc, followed by a_mc (and then the stage). Of couse at any point in that chain any event handler can use event.stopPropagation() to prevent that event from going any further up the chain.

AS3 also gives you the option to bubble events instead of capture them as its done above. Bubbling works in reverse order starting with the stage and then eventually reaching the child mc you clicked.

For onReleaseOutside, you would want to use bubbling since the stage is the first instance to recieve the event meaning no other handler can prevent that event from reaching the stage using event.stopPropagation() :)

csdstudio
07-21-2006, 06:02 PM
right. So when you click on something, that event starts at the object you clicked and then gets sent to each parent. Click on c_mc in a_mc.b_mc (a_mc.b_mc.c_mc) c_mc will get the event first, then b_mc, followed by a_mc (and then the stage). Of couse at any point in that chain any event handler can use event.stopPropagation() to prevent that event from going any further up the chain.

AS3 also gives you the option to bubble events instead of capture them as its done above. Bubbling works in reverse order starting with the stage and then eventually reaching the child mc you clicked.

For onReleaseOutside, you would want to use bubbling since the stage is the first instance to recieve the event meaning no other handler can prevent that event from reaching the stage using event.stopPropagation() :)

Ahh, now it starts to make sense. Thanks!