Share Posted January 17, 2012 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 comment Share on other sites More sharing options...
Share Posted January 18, 2012 You could loop through the targetObjects and use getBounds() to get each Rectangle and see if your selection Rectangle contains/overlaps it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now