767 posts
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 more
outandouter
says

I just encountered a little stopDrag() bug that is bugging me for quite some time now.

This example online should show you what I mean:

http://www.escapetheory.com.au/blog/tag/as3/

Just click that ball and drag it all the to the edge of screen, move the mouse outside the flash window. The flash won’t register mouse movements outside flash window which is obvious. Now, mouse still being outside the flash window, if you release the mouse button, you’ll see the bug. As soon as you release the mouse button, flash registers mouse position even if it is outside flash window and moves the ball to that place. Bring the mouse back to the flash window to see what actually happened.

My problem is similar to this and I want to decent work around for this.

Thanks!

1163 posts
  • Affiliate Level 2
  • Author Level 6
  • Collector Level 3
  • Top Monthly Author
+6 more
FlashTang
says

stage.addEventListener(MouseEvent.MOUSE_UP,function(e){trace(“ok”)})

767 posts
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 more
outandouter
says

stage.addEventListener(MouseEvent.MOUSE_UP,function(e){trace(“ok”)})

yea, that’s what I did. On this event, the stopDrag on ball is called. Everything works fine except just before stopping drag on the ball, the ball’s position is updated according to mouse position which is outside flash window.

180 posts
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 2
  • Exclusive Author
+1 more
LfO
says

Maybe you can try the MOUSE _LEAVE handler,.

stage.addEventListener(Event.MOUSE_LEAVE, leaveHandler);

The ball should drop the where the mouse leaves the swf.

3402 posts
  • 8 Years of Membership
  • Affiliate Level 6
  • Author Level 8
  • Beta Tester
+8 more
vuzum
says

It’s not a Flash bug, it’s a bug in your code. :-)

You need to detect when the mouse moves outside of the swf, and consider it a release, and do the proper action. You know that 90% of developers don’t take this into consideration? You can see this bug on a lot of Google Flash components as well. :D

Send me an email so I can give you a link to a free file done properly, and you can take the code from there. What we’ve done at Vuzum is create handlers for all states, and we add an event handler to any movieclip we want to have actions on, like this: mcName.addEvents(pathToWhereTheFunctionsAreDefinedUsuallyThis);

And then write the functions definitions, like: http://pastie.org/1708931

Ignore the switches and only see the functions and their parameters. It’s a copy/paste from whatever project I have opened right now.

And the prototype function looks like this: http://pastie.org/1708935

Basically those are the events you need to check for all possible states. I think this is the most up to date file, if not shoot me an email and I’ll send the link I mentioned initially. Good luck! :)

767 posts
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 more
outandouter
says

Maybe you can try the MOUSE _LEAVE handler,.

stage.addEventListener(Event.MOUSE_LEAVE, leaveHandler);

The ball should drop the where the mouse leaves the swf.

It’s not a Flash bug, it’s a bug in your code. :-)

You need to detect when the mouse moves outside of the swf, and consider it a release, and do the proper action. You know that 90% of developers don’t take this into consideration? You can see this bug on a lot of Google Flash components as well. :D

Send me an email so I can give you a link to a free file done properly, and you can take the code from there. What we’ve done at Vuzum is create handlers for all states, and we add an event handler to any movieclip we want to have actions on, like this: mcName.addEvents(pathToWhereTheFunctionsAreDefinedUsuallyThis);

And then write the functions definitions, like: http://pastie.org/1708931

Ignore the switches and only see the functions and their parameters. It’s a copy/paste from whatever project I have opened right now.

And the prototype function looks like this: http://pastie.org/1708935

Basically those are the events you need to check for all possible states. I think this is the most up to date file, if not shoot me an email and I’ll send the link I mentioned initially. Good luck! :)

Yea, I’ve tried something like. What I actually wanted to do was not to consider MOUSE _LEAVE or MOUSE _OUT as MOUSE _UP since I’m working on something way complex than a simple ball drag/drop. Anyways, I think there is no decent way to achieve that, so I’d have to find a dirty workaround for this. :)

Thanks for the help!

1163 posts
  • Affiliate Level 2
  • Author Level 6
  • Collector Level 3
  • Top Monthly Author
+6 more
FlashTang
says


stage.addEventListener(MouseEvent.MOUSE_UP,function(e){trace(“ok”)})
yea, that’s what I did. On this event, the stopDrag on ball is called. Everything works fine except just before stopping drag on the ball, the ball’s position is updated according to mouse position which is outside flash window.

Did you use stage
I mean add a MOUSE _UP event for stage
ball.addEventListener(MouseEvent.MOUSE_UP, ballUpHandler); stage.addEventListener(MouseEvent.MOUSE_UP, ballUpHandler);

it will resolve this “bug”

var ball=new Sprite()
ball.graphics.beginFill(0xff)
ball.graphics.drawRect(-20,-20,40,40)
ball.x=200
addChild(ball)
stage.frameRate=30
addEventListener(Event.ENTER_FRAME,loop)
ball.addEventListener(MouseEvent.MOUSE_DOWN,mh)
//ball.addEventListener(MouseEvent.MOUSE_UP,mh)
stage.addEventListener(MouseEvent.MOUSE_UP,mh)
var vy:Number=0
var vys:Number=1
var bIsD:Boolean
function loop(e):void{
    if(!bIsD){
    if(ball.y<stage.stageHeight-ball.height*.5){
        ball.y+=vy+=vys
    }else{

        ball.y=stage.stageHeight-ball.height*.5
    }
    }
    if(ball.x<=ball.width*.5){
        ball.x=ball.width*.5
    }
    if(ball.x>=stage.stageWidth-ball.width*.5){
        ball.x=stage.stageWidth-ball.width*.5
    }
}

function mh(e:MouseEvent):void{
    if(e.currentTarget==ball){
        if(e.type==MouseEvent.MOUSE_DOWN){
            bIsD=true
            vy=0
            ball.startDrag()
        }

    }
    if(e.type==MouseEvent.MOUSE_UP){
            bIsD=false
            ball.stopDrag()

    }
}
1163 posts
  • Affiliate Level 2
  • Author Level 6
  • Collector Level 3
  • Top Monthly Author
+6 more
FlashTang
says
Another one
var ball=new Sprite()
ball.graphics.beginFill(0xff)
ball.graphics.drawRect(-20,-20,40,40)
ball.x=200
addChild(ball)
stage.frameRate=30
addEventListener(Event.ENTER_FRAME,loop)
ball.addEventListener(MouseEvent.MOUSE_DOWN,mh)
//ball.addEventListener(MouseEvent.MOUSE_UP,mh)
stage.addEventListener(MouseEvent.MOUSE_UP,mh)
var vy:Number=0
var vys:Number=1
var bIsD:Boolean
function loop(e):void{
    if(!bIsD){
    if(ball.y<stage.stageHeight-ball.height*.5){
        ball.y+=vy+=vys
    }else{

        //ball.y=stage.stageHeight-ball.height*.5
    }
    }
    if(bIsD){
        ball.x=mouseX-memoryMX
        ball.y=mouseY-memoryMY
    }
    if(ball.x<=ball.width*.5){
        ball.x=ball.width*.5
    }
    if(ball.x>=stage.stageWidth-ball.width*.5){
        ball.x=stage.stageWidth-ball.width*.5
    }
    if(ball.y>=stage.stageHeight-ball.height*.5){
        ball.y=stage.stageHeight-ball.height*.5
    }

}
var memoryMY:Number
var memoryMX:Number
function mh(e:MouseEvent):void{
    if(e.currentTarget==ball){
        if(e.type==MouseEvent.MOUSE_DOWN){
            bIsD=true
            vy=0
            memoryMY=ball.mouseY
            memoryMX=ball.mouseX
            //ball.startDrag()
        }

    }
    if(e.type==MouseEvent.MOUSE_UP){
            bIsD=false
            //ball.stopDrag()

    }
}

767 posts
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 more
outandouter
says

@FlashTang I did try to use MOUSE _UP listener on stage but the bug is not with the listener rather with the stopDrag() thing (I think). When I call stopDrag(), just before stopping drag on the ball, it updates the ball position which it shouldn’t.

Your second solution, however, should work but I can’t use it as it is since my case is more complex. I’ve found another solution which works with me.

Thanks alot, btw. I really really appreciate!!!

3072 posts
  • Affiliate Level 3
  • Author Level 6
  • Collector Level 2
  • Weekly Top Seller
+7 more
wickedpixel
says

the point is.. never use start/stop drag functions. they are crappy. use the combination mouseDown/mouseMove/mouseUp instead.

by
by
by
by
by
by