SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make movie clip move in relation to another

    Hi all,

    I have been developing an AS3 menu for some time. I have got very close to completing it, i am just missing one thing.

    The menu works as follows: My stage is 960px wide. On the stage there is a holding MC called container_mc which is 1900px wide. Within this holding MC there are 6 buttons which fill up the entire dimensions of the MC. This container_mc sits on the stage and the sure can click and drag this container about horizontally thus revealing all of the buttons. When they click it opens up a box. When the box is closed the menu comes back. All of this works perfectly.

    I am now trying to integrate a movieclip, lets call it markermc that sits underneath the container_mc on the stage. Now, as the menu is dragged i want this markermc to move relative to the container_mc. So if the container_mc is being dragged left, at the same time i want the markermc to move right or if the container_mc is being dragged right then the markermc needs to move left. The reason i want this is because it will give a visual clue as to where you are on the menu. A working example of this can be seen at newcruelty.com

    The container_mc's starting X position is 20px on the stage. This is the same starting position for the markermc. The container_mc can be dragged as far as -960px for its X position. When the container_mc is at this point, then the marker MC needs to be at 960px. Basically i am trying to get the markermc to move inversely to the container_mc.

    Now, the code that controls the movement of the container_mc is as follows, and it is done on MOUSE_MOVE (it uses TweenLite).

    Code:
    var oldX:Number;
    var tarX:Number;
    
    TweenLite.killTweensOf(container_mc);
    tarX=Math.round(container_mc.x+(mouseX - oldX));
    tarX=Math.min(Math.max(tarX,-960),20);
    TweenLite.to(container_mc, 1, {x:tarX, ease:Strong.easeOut});
    I am pretty sure that to make the markermc i can reuse this code, changing certain bits but i am not sure how to do it. I think that is should too be placed on the same MOUSE_MOVE function. This is my attempt and it is not working as i am not sure how to find the inverse:

    Code:
    var trackX:Number;
    
    TweenLite.killTweensOf(markermc);
    trackX=Math.round(container_mc.x/1));
    trackX=Math.min(Math.max(tarX, 960),20);
    TweenLite.to(markermc, 1, {x:trackX, ease:Strong.easeOut});
    If anyone could help me that would be great. I have attached a CS4 FLA and a compiled SWF for you to have a look at.

    Many thanks

    Matt
    Attached Files Attached Files


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
  •