actionscript 3 - Check when a part of the MovieClip leaves the Stage -
i'm creating drag , drop game using as3, want check when apart of movieclip outside screen move view behind , let user choose drop it.
i cant' test if movieclip credentials bigger stage (scalemode = no_scale) width/height, because there part of stage it's hidden behind browser window.
it's same aspect mouse_leave time has movieclips, tried see code behind mouse_leave couldn't reach it.
thank you.
main class
[swf(width='800', height='800',backgroundcolor='#cc99ff', framerate='60')] public class dragtest extends sprite { public function dragtest() { addchild(new world(this)); this.stage.scalemode = "noscale"; this.stage.align = "tl"; this.graphics.linestyle(5,0x555555,0.5); this.graphics.drawrect(0,0,800,800); } }
world class
public class world extends container // container swc { private var _display:sprite; private var _dragpt:point; private var _dragedobject:movieclip; public function world(display:sprite) { super(); _display = display; mymc.addeventlistener(mouseevent.mouse_down, onpickup, false, 0, true ); display.stage.addeventlistener(mouseevent.mouse_up, ondrop, false, 0, true ); display.stage.addeventlistener(event.mouse_leave, onmouseleave, false, 0, true ); } protected function onmouseleave(event:event):void { trace("mouse leaving stage"); } protected function ondrop(e:mouseevent):void { _display.stage.removeeventlistener(mouseevent.mouse_move, onmoveobject); } private function onpickup(e:mouseevent) { _dragedobject = e.currenttarget movieclip; _display.stage.addeventlistener(mouseevent.mouse_move, onmoveobject, false, 0, true); } protected function onmoveobject(e:mouseevent):void { var point:point = new point(_display.stage.mousex, _display.stage.mousey); (_dragedobject movieclip).x = point.x; (_dragedobject movieclip).y = point.y; } }
here example : simple code
the easiest approach use getbounds(stage)
, compare stagewidth
, stageheight
:
var bounds:rectangle = _draggedobject.getbounds(stage); if (bounds.left < 0) { // left part of object off-screen } else if (bounds.right > stage.stagewidth) { // right part of object off-screen } if (bounds.top < 0) { // top part of object offscreen } else if (bounds.bottom > stage.stageheight) { // bottom part of object off-screen }
you move display
in each of these cases.
Comments
Post a Comment