A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: i want to have an mc move left and right depending on where the user's mouse goes.

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Posts
    231

    i want to have an mc move left and right depending on where the user's mouse goes.

    Basically, I have a photo gallery, on a long horizontal strip. I want the user to navigate this strip by simply moving their mouse to the right to make it move right, and moving their mouse to the left to make it move left.

    I know that there is a way to do this where you track the mouse whereever it is on the stage...but I'd only like it to be only active when it is over this particular strip.

    Also, each thumbnail on this strip has a rollover effect. I would like to have that roll over effect stay active...

    Any help would be appreciated.

    Thanks.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Depending if the strip is a button or a movieclip, you'd use button or movieclip events to trigger the moving function, and yes you'll need to detect mouse position via _xmouse and _ymouse. Look at the Tween Class for more interesting movements if you're working with flash8.

    gparis

  3. #3
    Senior Member onine's Avatar
    Join Date
    Mar 2005
    Posts
    627
    Check out the "Scrolling Thumbnail Panel" tutorial at:

    http://gotoandlearn.com/download.php

    You'll have to download the video tutorial (it's an .flv) and the .flv player he recommends.

    It's worth it anyway. It's a good tute.

  4. #4

  5. #5
    Senior Member
    Join Date
    Apr 2004
    Posts
    231
    crequin, yes, but how do I make the strip actually move left and right, with easing?

  6. #6
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    well, that's a bit different, and in fact a bit easier to accomplish. what you'll need to do is lay out your strip within a movieclip with your first menu item left top aligned to 0,0. Then you'll use the xmouse values proportionally to the width of your stage (or mask) to move your strip. Here's an example:

    PHP Code:
    //myStrip is the menu with all the items in it
    function onEnterFrame (){
        
    newX = (Stage.width myStrip._width) * _xmouse;
        
    myStrip._x newX

    to use an easing, you can use the tween class:
    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.Regular;

    var 
    myTween:Tween = new Tween(myStrip"_x"Regular.easeOutmyStrip._x08false);
    function 
    onEnterFrame (){
        var 
    newX = (Stage.width myStrip._width) * -_xmouse;
        
    myTween.continueTo(newX8);


  7. #7
    Senior Member
    Join Date
    Apr 2004
    Posts
    231
    that code is based on the stage width...what if I wanted it to be based on some MC that is less than the stage width.

    So that it would be activated only when you are over that particular MC>

  8. #8
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    my calculation of the newX values was sloppy before. To calculate the _x values properly, you need to move the strip a proportion of the difference between the strip total length and the stage width per _xmouse. Use this script instead.

    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.Regular;

    var 
    myTween:Tween = new Tween(myStrip"_x"Regular.easeOut008false);
    function 
    onEnterFrame (){
        var 
    newX = -_xmouse * ((myStrip._width Stage.width) / Stage.width);
        
    myTween.continueTo(newX8);


  9. #9
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    to make it based on a MC, just change all the Stage.width calls to your limiting MC._width calls. you'll probably also want to add an if statement that checks to see if the mouse is within your limiting clip.

    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.Regular;

    var 
    myTween:Tween = new Tween(myStrip"_x"Regular.easeOut008false);
    function 
    onEnterFrame (){
        if (
    _xmouse >= myLimit._x && _xmouse <=  myLimit._x myLimit._width && _ymouse >= myLimit._y && _ymouse <=  myLimit._y myLimit._height){
            var 
    newX = -_xmouse * ((myStrip._width myLimit._width) / myLimit._width);
            
    myTween.continueTo(newX8);
        }


  10. #10
    Senior Member
    Join Date
    Apr 2004
    Posts
    231
    that thing with the myLimit mc doesn't seem to work.

    Like, let's say you want the active MC that limits it, to be half the size of the stage width.

    Try it out in an fla....the strip mc flys off the screen, when you roll over the limit mc.

    something is off.

    ???

  11. #11
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    You're right, I dodged when I should have weaved. Try this.

    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.Regular;

    var 
    myTween:Tween = new Tween(myStrip"_x"Regular.easeOutmyLimit._xmyLimit._x8false);
    function 
    onEnterFrame (){
        if (
    _xmouse >= myLimit._x && _xmouse <=  myLimit._x myLimit._width && _ymouse >= myLimit._y && _ymouse <=  myLimit._y myLimit._height){
            var 
    dx myStrip._width myLimit._width;
            var 
    xPosPercent myLimit._xmouse myLimit._width;
            
            var 
    newX myLimit._x xPosPercent dx;
            
    //myStrip._x = newX;
            
    myTween.continueTo(newX8);
        }


  12. #12
    Senior Member
    Join Date
    Apr 2004
    Posts
    231
    that works well. Sweet. Now, what if I wanted to use mc_tween, instead of the mx.transitions.

    Mc_tween has a nice "easeOutExpo", that I think would work well.


    THANKS

  13. #13
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    I don't know mc_tween. perhaps it's possible... but simply changing Regular to Strong (in both places might just give you what you're looking for... try Elastic too, while you're at it

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