Return to Snippet

Revision: 8780
at October 7, 2008 11:34 by linkage


Initial Code
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');	
		}

Initial URL
http://wiki.github.com/tschneidereit/reprise

Initial Description

                                

Initial Title
reprise - drag element

Initial Tags

                                

Initial Language
ActionScript 3