/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private function createTestDragItem() : void { m_dragObject = m_rootElement.addComponent('dragElvis'); m_dragObject.addEventListener(MouseEvent.MOUSE_DOWN, dragObject_mouseDown); m_dragObject.addEventListener(MouseEvent.MOUSE_UP, dragObject_mouseUp); } private function dragObject_mouseUp(event : MouseEvent) : void { UIComponent(event.currentTarget).removeEventListener(Event.ENTER_FRAME, drag_enterFrame); } private function dragObject_mouseDown(event : MouseEvent) : void { m_mousePositionOverCurrentDragObject = new Point(event.localX, event.localY); UIComponent(event.currentTarget).addEventListener(Event.ENTER_FRAME, drag_enterFrame); } private function drag_enterFrame(event : Event) : void { var leftPosition : Number = Math.min(mouseX - m_mousePositionOverCurrentDragObject.x, 600); leftPosition = Math.max(leftPosition, 0); var topPosition : Number = Math.min(mouseY - m_mousePositionOverCurrentDragObject.y, 300); topPosition = Math.max(topPosition, 0); m_dragObject.setStyle('left', leftPosition + 'px'); m_dragObject.setStyle('top', topPosition + 'px'); }
URL: http://wiki.github.com/tschneidereit/reprise