views:

38

answers:

1

Hi:

I'm in the midst of creating a Bumptop styled selection tool. Right now I got as far as creating the tool itself (which actually works pretty good) and spreading some random square items on the stage. This is the class that creates the selection tool :

package com.reyco1.medusa.selectiontool
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;

    public class SelectionBase extends Sprite
    {
        private var points:Array = [];

        public function SelectionBase()
        {
            super();
            addEventListener(Event.ADDED_TO_STAGE, initialize);
        }

        private function initialize(e:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, initialize);

            points.push(new Point(mouseX, mouseY));          stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
        }

        private function handleMouseMove(e:MouseEvent):void
        {           
            graphics.clear();

            graphics.beginFill(0x33CCFF, .5);
            graphics.drawCircle(0, 0, 20);
            graphics.endFill();

            graphics.moveTo(0, 0);
            graphics.lineStyle(1.5, 0x33CCFF, .5);
            graphics.lineTo(mouseX, mouseY);

            points.push(new Point(mouseX, mouseY));

            graphics.beginFill(0x33CCFF, .1);
            graphics.moveTo(points[0].x, points[0].y);

            for (var i:uint = 1; i < points.length; i++)
            {
                graphics.lineTo(points[i].x, points[i].y);
            }

            graphics.lineTo(points[0].x, points[0].y);
            graphics.endFill();

            dispatchEvent(new Event("UPDATE"));
        }

        public function clear():void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
            graphics.clear();
        }
    }
}

And this is the document class that implements it :

package
{
    import com.reyco1.medusa.selectiontool.SelectionBase;

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;

    [SWF(width = '1024', height = '768', backgroundColor = '0x000000')]
    public class SelectionToolPrototype extends Sprite
    {
        private var selectionTool:SelectionBase;

        public function SelectionToolPrototype()
        {                         
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.MEDIUM;
                    stage.addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
            stage.addEventListener(MouseEvent.MOUSE_UP,     handleUp);  

            placeShapesRandomly();
        }

        private function placeShapesRandomly():void
        {
            for(var a:Number = 0; a<25; a++)
            {
                var s:Sprite = new Sprite();
                s.graphics.beginFill(Math.random() * 0xCCCCCC);
                s.graphics.drawRect(0, 0, 50, 50);
                s.graphics.endFill();
                s.x = Math.floor(Math.random() * 900 - 40) + 40;
                s.y = Math.floor(Math.random() * 700 - 40) + 40;
                s.rotation =  Math.floor(Math.random() * 360 - 40) + 40;
                s.buttonMode = true;
                addChild(s);
            }
        }

        private function handleUp(e:MouseEvent):void
        {
            selectionTool.removeEventListener("UPDATE", handleToolUpdate);
            removeChild(selectionTool);
            selectionTool = null;
        }

        private function handleDown(e:MouseEvent):void
        {
            selectionTool = new SelectionBase();
            selectionTool.addEventListener("UPDATE", handleToolUpdate);
            selectionTool.x = mouseX;
            selectionTool.y = mouseY;
            addChild(selectionTool);
        }

        private function handleToolUpdate(e:Event):void
        {
            // logic to determin if items are within selection goes here        
        }
    }
}

I've tried using collision detection by means of BitmapData and even using collision libraries like CDK but I cant get anything to work. Anybody have an idea what I should use in the handleToolUpdate(e:MouseEvent); ? Thanks!

A: 

I'll break it down. Basically I am trying to create a prototype of the BumpTop Lasso or Selection tool.

I need help in finding out which objects either collide or have a point within the bounds of the drawn lasso.

I have upload what I have so far to my server here : http://labs.reyco1.com/bumptop/SelectionToolPrototype.html. You can see the source by right clicking and selecting "View Source".

Like I said in my earlier post, I tried using Bitmapdata collision testing and even tried using the Collision Detection Kit to no avail. Thanks in advance.

Reynaldo Columns