×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Swapping Image *Positions*

Swapping Image *Positions*

Swapping Image *Positions*

(OP)
Greetings all---new forum member here...

I am hitting a wall as to how to achieve the following in Director (I'm using 8.5):

I have 7 objects on the stage, and I want the user to be able to click two of them, have them each "highlight" (or otherwise show their status as "selected"), then, when a button is pressed (one which says, "Swap" or a synonym), the two selected objects trade positions.  To complicate things further, I need the two objects to trade their positions *visibly*---not as an instantaneous "flip," but, rather, the user can see the first object travel to the second's position and vice versa.

I've only got rudimentary Lingo expertise and I'm fearing that I'm out of my depth here.

Any help that can be offered would be greatly appreciated.



Regards,

Adam
Los Angeles, CA

RE: Swapping Image *Positions*

Let's start with the simplest example: swap locations of two objects.

The set up:
Place one object in Sprite 1, another object in Sprite 2. Place "Swap" button in Sprite 3.

The scripts:
1. Movie script:
--
on prepareMovie
  global gSwapPList
  gSwapPList = [:]
end prepareMovie
--


2. Behaviour script attached to the "Swap" button:
--
on mouseUp me
  global gSwapPList
  if gSwapPList.length < 1 then
    gSwapPList = [#1: [#sprite: 1, #x: sprite(1).locH, #y:sprite(1).locV], #2: [#sprite: 2, #x: sprite(2).locH, #y: sprite(2).locV]]
  end if
end mouseUp
--


3. Frame script:
--
on exitFrame me
  global gSwapPList
  if gSwapPList.count > 1 then
    spriteA = sprite(gSwapPlist[#1][#sprite])
    spriteATargetLocH = gSwapPlist[#2][#x]
    spriteATargetLocV = gSwapPlist[#2][#y]
    if spriteA.locH <> spriteATargetLocH then
      spriteA.locH = spriteA.locH + (spriteATargetLocH - spriteA.locH)/10
    end if
    if spriteA.locV <> spriteATargetLocV then
      spriteA.locV = spriteA.locV + (spriteATargetLocV - spriteA.locV)/10
    end if
    spriteB = sprite(gSwapPlist[#2][#sprite])
    spriteBTargetLocH = gSwapPlist[#1][#x]
    spriteBTargetLocv = gSwapPlist[#1][#y]
    if spriteB.locH <> spriteBTargetLocH then
      spriteB.locH = spriteB.locH + (spriteBTargetLocH - spriteB.locH)/10
    end if
    if spriteB.locV <> spriteBTargetLocV then
      spriteB.locV = spriteB.locV + (spriteBTargetLocV - spriteB.locV)/10
    end if
  end if
  go the frame
end
--

Kenneth Kawamoto
www.materiaprima.co.uk

RE: Swapping Image *Positions*

(OP)
Dear Kenneth:

Apologies for the one-week delay---I got sidetracked by totally unrelated projects...

Returning to this matter today, I found your post to be very smart, clean, simple, clear, and (as it turns out), highly effective.

It has served not only to solve my problem but as a Lingo programming lesson all of its own.  It has helped me to deepen my understanding of how Lingo works with lists, handlers, etc.  I am extremely grateful.


Warmest regards,

Adam LeBow
Los Angeles, CA, USA

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close