SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    saving the x and y coordinates inside a movie clip... how?

    basically, we have a drag-and-drop concept for this one. there's a set of draggable symbols that are movie clips, and once they're placed inside another movie clip, we want to save it's placement on said clip. that means getting their x and y coordinates right?

    the question is, how do we do this using by listing the draggable symbols in arrays?

    basically, we have this script inside the movable symbols:


    onClipEvent(load){

    var xorig=this._x;
    var yorig=this._y;
    var point= new Object()
    point.x=0;
    point.y=0;


    }

    onClipEvent(mouseDown){

    if(hitTest(_root._xmouse, _root._ymouse, false)){
    this.gotoAndPlay("pick");
    this.startDrag();
    }
    }

    onClipEvent(mouseUp){

    if(this.hitTest(_root.skins)){
    this.gotoAndPlay("drop");
    this.stopDrag();

    point.x=_root._xmouse;
    point.y=_root._ymouse;
    this.globalToLocal(point);
    this.localx = point.x;
    this.localy = point.y;
    trace (this.localx);
    trace (this.localy);
    trace ("tracing");

    if(!this.hitTest(_root._xmouse, _root._ymouse)){
    gotoAndStop(1);
    }

    }

    else{
    this.stopDrag();
    this._x=xorig;
    this._y=yorig;
    this.gotoAndStop(1);
    }
    what?!?

  2. #2
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there...I'm not 100% if I get what you want exactly but A way to store co÷rdinates (for later retrieval) is by creating a function that fills up two array's with (x and y co÷rdinates).

    the code below is triggered by sending a pair of x,y coordinates to the recordCoords() function e.g. recordCoords(150,20) will add these co÷rdinates to the list of coordinates stored in the xArray and yArray.


    inititialisation code:
    Code:
    xArray = new array();
    yArray = new array();
    count=0;

    Code:
    function recordCoords(x,y) {
       xArray[count]=x;
       yArray[count]=y;
       count++;
    }
    if it's something completely different you're after, please try to explain a bit more...
    Last edited by flux; Feb 24, 2002 at 13:44.

  3. #3
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's very similar! thanks!

    but where do i embed the code? onClipEvent(load)? and if i'm to create another array for the different clips to be saved, would the code come out as such:

    Code:
    xArray = new Array();
    yArray = new Array();
    symbolsArray = new Array();
    count = 0;
    
    
    function RecordCoords(symbols, x, y) {
         symbolsArray[count] = symbols;
         xArray[count] = x;
         yArray[count] = y;
    }


    thank you so much again! you're a lifesaver!
    Last edited by ralphot; Feb 25, 2002 at 11:49.
    what?!?

  4. #4
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's the real flow:

    we have a bunch of draggable movie clips on the main timeline, and will be dropped on a certain movie clip we call "skins". so we used the globalToLocal function so as we can map out their coordinates on the "skins" movie clip.

    then, on another frame, the "skins" movie clip will be called again, only this time all the draggable clips dropped onto it are tucked nicely where they where placed earlier.
    what?!?

  5. #5
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by ralphot
    but where do i embed the code? onClipEvent(load)? and if i'm to create another array for the different clips to be saved, would the code come out as such:
    the initialization code (and definition of functions) is best placed into an onClipevent(load) as it is ideal to initialize things...you should however make sure the symbol never gets cleared from stage, because then all the variables, defined in that symbol will be lost as well...if this is the case you can either create a special movieclip to hold the array values, or even use the main timeline (_root.)

    For complex projects with a lot of variables involved, I create one (or more) empty movieclip(s) on stage and give it an instance name of _root.vars. I use it to hold all the variables I need...

    to replace dragged objects on the skins movieclip you can use a simple loop...make sure though the dragged clips are named as follows, (clip0, clip1, clip2, clip3,...). As you already mentioned, you can add another array to store the name of the clip (symbolsarray).

    Code:
    for (i=0; i<=xArray.length; i++) {
    
        //see what clip is next in the row
        target="_root.clip"+symbolsArray[i];
    
        //set the clip back to the original co÷rdinates
        target._x = xArray[i];
        target._y = yArray[i];
    
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •