actionscript-3tilelist

AS3: Drag to select multiple tiles in TileList


Im working a project with two of my fellow students and we would like to be able to drag the cursor over a tilelist to select multiple tiles. We cant really find any function to do this, is it possible to do it some how?

Best regards

Thanks


Solution

  • This should give you an idea of what you want to accomplish:

    tileList = new TileList();
    tileList.allowMultipleSelection = true;
    tileList.addEventListener(MouseEvent.MOUSE_DOWN, startSelecting);
    tileList.addEventListener(MouseEvent.MOUSE_UP, stopSelecting);
    
    function startSelecting(e:MouseEvent):void 
    {
        tileList.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        if (CellRenderer(e.target))
        {
            CellRenderer(e.target).selected = true;
        }
    }
    
    function onMouseMove(e:MouseEvent):void 
    {
        if (CellRenderer(e.target))
        {
            CellRenderer(e.target).selected = true;
        }
    }
    
    function stopSelecting(e:MouseEvent):void 
    {
        tileList.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    }
    

    You'll definitely want to customize this to suit your needs, but basically it adds a few mouse event listeners to the tile list and selects any tile that has been rolled over while the mouse button is pressed.