Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
artlover

[Flex] how do I select to object

Recommended Posts

How do I select the object with a rectangle

how do i tm update selection ????

 

im sorry bad eng :)

 

AS3 codes

public function build($color:uint):void
	{
		var selectionRect:Rectangle;
		var selectionSprite:Sprite=new Sprite();
		var isMouseHeld:Boolean=false;

		addChild(selectionSprite);
		stage.addEventListener(MouseEvent.MOUSE_DOWN, SetStartPoint);
		stage.addEventListener(MouseEvent.CLICK, RemoveRectangle);

		function SetStartPoint(evt:MouseEvent):void
		{
			selectionRect=new Rectangle(stage.mouseX, stage.mouseY);
			isMouseHeld=true;
			stage.addEventListener(MouseEvent.MOUSE_UP, RemoveRectangle);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, UpdateRectangle);
		}

		function RemoveRectangle(evt:MouseEvent):void
		{
			selectionSprite.graphics.clear();
			isMouseHeld=false;
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, UpdateRectangle);
			stage.removeEventListener(MouseEvent.MOUSE_UP, RemoveRectangle);
		}


		function UpdateRectangle(evt:MouseEvent):void
		{
			selectionSprite.graphics.clear();

			if (isMouseHeld)
			{
				selectionRect.width=stage.mouseX - selectionRect.x;
				selectionRect.height=stage.mouseY - selectionRect.y;
				selectionSprite.graphics.beginFill($color, .1);
				selectionSprite.graphics.lineStyle(2, $color, .5);
				selectionSprite.graphics.drawRect(selectionRect.x, selectionRect.y, selectionRect.width, selectionRect.height);
				selectionSprite.graphics.endFill();
				CheckForSelection();
			}
		}

		function CheckForSelection():void
		{
			for (var i:int=0;i				{
				if (stage.hitTestObject(selectionSprite))
				{
					------ ?????? ------
				}
				else
				{

				}
			}
		}

	}

 

flex root codes





Link to post
Share on other sites

You could loop through the targetObjects and use getBounds() to get each Rectangle and see if your selection Rectangle contains/overlaps it.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×