Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 516341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:43:17+00:00 2026-05-13T07:43:17+00:00

I want to implement drag&drop possibilities in my application. Here is my source code:

  • 0

I want to implement drag&drop possibilities in my application. Here is my source code:

I added images to the container, and now want to be able to move them from element PieceContainer to element board (defined in the another class). I tried to define mouse move handler as it was shown here: http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_7.html, but it doesn’t do anything… Actually I don’t understand how should I define drap initiator, and drop handler

public class PieceContainer extends Canvas
{
    //private var image:Image = new Image();
    private var piecesWhite:Dictionary;
    private var piecesBlack:Dictionary; 
    private var images:ArrayCollection = new ArrayCollection();
    private var placeX:Number;

    public var items:Dictionary;

    public function PieceContainer()
    {
        super();
        this.addEventListener(Event.ADDED_TO_STAGE, displayPiece);
    }

    private function displayPiece(event:Event):void
    {
        placePiecesDict(new Point(0, 0), items);
    }

    private function placePiecesDict(start:Point, dict:Dictionary):void
    {
        placeX = 0;
        for (var item:* in dict)
    {

            var image:Image = new Image();
                image.source = dict[item];
                image.x = placeX/1.4;
                image.y = start.y;
                image.addEventListener(MouseEvent.MOUSE_MOVE, doDrag);
                images.addItem(image);
                this.addChild(image);
            placeX += height; 
            }
        }


        private function doDrag(evt:Event):void
        {
            trace(evt);
        }
    }

Please also see attached image for some more description:
http://img.skitch.com/20091221-e6j8d62y9iin621hmcdbssrp6d.png


I reorganized code this way:

public class PieceContainer extends Canvas
{

    private var piecesWhite:Dictionary;
    private var piecesBlack:Dictionary; 
    private var images:ArrayCollection = new ArrayCollection();
    private var placeX:Number;  
    public var items:Dictionary;

    public function PieceContainer()
    {
        super();
        this.addEventListener(Event.ADDED_TO_STAGE, displayPiece);
    }

    private function displayPiece(event:Event):void
    {
        placePiecesDict(new Point(0, 0), items);
    }

    private function placePiecesDict(start:Point, dict:Dictionary):void
    {
        placeX = 0;
        for (var item:* in dict)
        {

            var image:Image = new Image();
                     image.source = dict[item];
                     image.x = placeX/1.4;
                 image.y = start.y;
                 image.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
            images.addItem(image);
            this.addChild(image);
            placeX += height; 
        }
        }


    private function mouseMoveHandler(evt:MouseEvent):void
    {

        var dragInitiator:Image =  Image(evt.currentTarget);
        var ds:DragSource = new DragSource();
        ds.addData(dragInitiator, "img");
        DragManager.doDrag(dragInitiator, ds, evt);
    }

And also added drag and drop handlers to the board:

public class BoardCell extends Canvas
{

    private var _color:Number;

    public function BoardCell()
    {
        super();
        this.addEventListener(DragEvent.DRAG_ENTER, dragEnterHanler);
        this.addEventListener(DragEvent.DRAG_DROP, dragDropHandler);
    }

    public function placeMe(x:int, y:int, width:Number, color:Number):void
    {
        graphics.lineStyle(1, 0x000000);
        graphics.beginFill(color);
        graphics.drawRect(x, y, width, width);
        graphics.endFill(); 
    }


    private function dragEnterHanler(event:DragEvent):void
    {
        if(event.dragSource.hasFormat("img"))
        {
            DragManager.acceptDragDrop(Canvas(event.currentTarget))
        }
    }

    private function dragDropHandler(event:DragEvent):void
    {
        event.dragInitiator.x = 0;
        event.dragInitiator.y = 0;

    }

But actually have 2 problems:

First: Items are draggable, but when i add them to board they stays on in the PiecesContainer.
Second: I want items to be copied, rather then just moved (but when they are on board they should be movable, not copied)

Thanks, in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:43:17+00:00Added an answer on May 13, 2026 at 7:43 am

    First problem is easily fixed. dragMoveEnabled=true is how you do it in a list control, but since your doing something very custom you will want to look back at the drag initiator and delete the drug item from it. Details here:
    http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_8.html

    This will also help you set up your drag and drop functions so you can solve problem 2 as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use placement new: new (m_data) T(); Placement new is really… May 14, 2026 at 7:19 pm
  • Editorial Team
    Editorial Team added an answer First, the implicit operator allows for implcit conversions (no casting… May 14, 2026 at 7:19 pm
  • Editorial Team
    Editorial Team added an answer gethostbyname echo gethostbyname('stackoverflow.com'); // 69.59.196.211 You can use parse_url to… May 14, 2026 at 7:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.