dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: draging 2 opposite objects

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    10
    does anyone know how to communicate with 2 object. and make one follow the opposite motion of the one that you're dragging?

  2. #2
    Senior Front End Developper
    Join Date
    Dec 2000
    Location
    Montréal
    Posts
    568
    yes, you need an instance for both your movie clip
    let's say mc1 and mc2.

    on mc1 and mc2, put this code

    Code:
    onClipEvent(load)
    {
       this.orX = _x;
       this.orY = _y;
       this.bDrag = false;
    }
    then on mc1 only put

    Code:
    onClipEvent(mouseMove)
    {
    
       if (!bDrag)
         return;
    
        diffX = this._x - this.orX;
        diffY = this._y - this.orY;
    
        _root.mc2._x -= diffX;
        _root.mc2._y -= diffY;
    }
    Then when you start dragging add:

    Code:
    _root.mc1.StartDrag(...);
    _root.mc1.bDrag = true;
    and when you stop dragging

    Code:
    _root.mc1.StopDrag();
    _root.mc1.bDrag = false;

  3. #3
    Junior Member
    Join Date
    Mar 2002
    Posts
    10
    omg thank you soo much!!!, I travel from buttons to movies and to adding x and y, but never figure out the things behind that wall.
    thank you!!

  4. #4
    Junior Member
    Join Date
    Mar 2002
    Posts
    10
    hi, i did it, it works great, but just one alittle problem, when I drag it up it when down, but when I drag down it takes 2 times the distance to go back up, I'm assuming the math's doing the trick, is there a way to control the same distance to drag up and down??

  5. #5
    Senior Front End Developper
    Join Date
    Dec 2000
    Location
    Montréal
    Posts
    568
    ok try this instead

    Code:
    onClipEvent(load)
    {
       this.lastX = _x;
       this.lastY = _y;
       this.bDrag = false;
    }
    
    
    onClipEvent(mouseMove)
    {
       if (!bDrag)
         return;
    
        diffX = this._x - this.lastX;
        diffY = this._y - this.lastY;
    
        this.lastX = this._x;
        this.lastY = this._y;
    
        _root.mc2._x -= diffX;
        _root.mc2._y -= diffY;
    }

  6. #6
    Junior Member
    Join Date
    Mar 2002
    Posts
    10
    omg it's perfect!!! I mean it's perfect.
    thank you so much

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center