Показать сообщение отдельно
Старый 06.06.2014, 00:16
samana вне форума Посмотреть профиль Отправить личное сообщение для samana Найти все сообщения от samana
  № 2  
Ответить с цитированием
samana
 
Аватар для samana

блогер
Регистрация: Mar 2008
Адрес: Днепропетровск
Сообщений: 1,783
Записей в блоге: 3
Можно как-то так:
Код AS3:
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
 
	/**
	 * ...
	 * @author samana
	 */
	public class DragBlock extends Sprite 
	{
		static public const HORIZONTAL:String = "horizontal";
		static public const VERTICAL:String = "vertical";
 
		private var orient:String;
 
		public function DragBlock(w:Number,h:Number,orient:String) 
		{
			this.orient = orient;
 
			graphics.beginFill(0xCC00CC);
			graphics.drawRect(0, 0, w, h);
			graphics.endFill();
 
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
			addEventListener(Event.REMOVED_FROM_STAGE, removedFromStage);
		}
 
		private function removedFromStage(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, removedFromStage);
 
			removeEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMove);
			stage.removeEventListener(MouseEvent.MOUSE_UP, stage_mouseUp);
		}
 
		private function addedToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
 
			addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
		}
 
		private function mouseDown(e:MouseEvent):void 
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMove);
			stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUp);
		}
 
		private function stage_mouseUp(e:MouseEvent):void 
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMove);
			stage.removeEventListener(MouseEvent.MOUSE_UP, stage_mouseUp);
		}
 
		private function stage_mouseMove(e:MouseEvent):void 
		{
			if (orient == HORIZONTAL) x = parent.mouseX;
 
			if (orient == VERTICAL) y = parent.mouseY;
 
		}
 
	}
 
}


Последний раз редактировалось samana; 06.06.2014 в 00:38. Причина: Изменения в методе stage_mouseMove