Flash XML - drag and drop

Posted on 2005-05-10
Last Modified: 2009-12-16
I am making a virtual stock in Flash, with a number of shelfs each containing some pallets.

I have made the pallets as mc's, and I would like to be able to drag and move to empty spaces on one of the shelfs.
When I get a little further, I will  load the pallets positions and descriptive data from a xml file provided from a DB via a webservice, which I should write back to, when I move a pallet to a new space.

I hope you get the point...

So what I want, is some help to the actionscript for the dragging part:

when mc is dragged
if dropTarget = empty space
    snap to emty space
    (at some point - save new position to DB via a xml webservice)
   snap to original position

I found a similar question here on Experts Exchange Q_20566450 - but an answer was never provided. Hope somebody can help.
Question by:sotea
    LVL 18

    Accepted Solution

    pallet1_mc.onPress = function() {

    pallet1_mc.onRelease = function() {


    as a simple drag and test solution

    LVL 1

    Author Comment

    Thanks - but it doesn't work for me - I can startDrag, but it doesn't stopDrag on release.

    Just to be shure I'm getting this right.

    I paste your actionscript into the first frame of the movie.
    I create a movieclip with instance name "pallet1_mc"
    emptyspaces is just a variable declaring the position of empty spaces.
    LVL 18

    Expert Comment

    exactly right - make sure in the pallet mc that the pallet itself sits centred on 0,0 co-ordinates - if it is set to top left the drag will push it out of its own way (if that makes any sense!)

    LVL 1

    Author Comment

    Hi billystyx

    For some reason it didn't work for me  - I don't know why.
    A found another way to solve it - but thanks for the help anyway.

    My solution looks like this:
    Actionscript on the pallet mc:

    on (press) {

    on (release) {
      if (eval(this._droptarget) == {
            this._x =;
            this._y =;
      } else {
          this._x = _root.orgXpos;
          this._y = _root.orgYpos;

    orgXpos and orgYpos is declared in frame 1 in the movie.

    But I still need to think of what to do, if there is more than 1 free pallet space.
    LVL 18

    Expert Comment

    I will take a look tonight and test out my solution - see what I can come up with:)

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now