• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Flash XML - drag and drop

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)
else
   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.
0
sotea
Asked:
sotea
  • 3
  • 2
1 Solution
 
BillystyxCommented:
emptyspaces=[50,50],[50,100],[50,150]];
pallet1_mc.onPress = function() {
     pallet1_mc.startDrag(true);
     this.oldX=pallet1._x;
this.oldY=pallet1._y;

};
pallet1_mc.onRelease = function() {
for(i=0;i<emptyspaces;i++){
if(pallet1.hitTest(emptyspaces[i][0],emptyspaces[i][1])){
     pallet1_mc.stopDrag();
     this.hit=true;
emptyspaces.splice(i,1);
}
}
if(this.hit!=true){
pallet1_mc._x=oldX;
pallet1_mc._y=oldY;
}
this.hit=false;

     };

as a simple drag and test solution

Billystyx
0
 
soteaAuthor Commented:
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.
0
 
BillystyxCommented:
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!)

billystyx
0
 
soteaAuthor Commented:
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) {
      startDrag(this);
}

on (release) {
  if (eval(this._droptarget) == _root.free) {
      stopDrag();
        this._x = _root.free._x;
        this._y = _root.free._y;
  } else {
      stopDrag();
      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.
0
 
BillystyxCommented:
I will take a look tonight and test out my solution - see what I can come up with:)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now