It seem when I trying to drag the bordercontainer to move along x-axis position on mouse down. It appear to move stable but became jerky when I drag a little faster.
Any way to get bordercontainer move with smooth motion?
private function mDownHandler(e开发者_Python百科vent:MouseEvent):void {
gMouseX = event.localX;
borderCntr.addEventListener(MouseEvent.MOUSE_MOVE, mMoveHandler);
}
private function mMoveHandler(event:MouseEvent):void {
borderCntr.x = int(event.localX)-gMouseX;
}
are you targeting mobile devices? MouseEvent.MOUSE_MOVE
is quite intensive for mobile devices since it calls many more times faster than the framerate. it's not optimized nor recommended to use MouseEvent.MOUSE_MOVE
for projects with mobile deployment targets.
instead, create your own moving logic by employing either the stageX
and stageY
properties or startDrag()
and stopDrag()
functions with an Event.ENTER_FRAME
event.
1) You shouldn't use local coordinates in your mMoveHandler
, because it's coordinates of mouse inside borderCntr
- it simply couldn't work as you wish to. Use parent's or top level application's mouseX
or simply event.stageX
.
2) Don't add MouseEvent.MOUSE_MOVE
listener to borderCntr
. When you will make very quick movement and mouse will walk outside borderCntr
, you simply won't recieve move events anymore. Instead listen to parent or stage or top level application (again), the one that would not loose mouse.
精彩评论