A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 38

Thread: Slide object in on mouseover

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Slide object in on mouseover

    Hi, I'd like to figure out how to do this (I think in AS3).

    I'd like to mouseover an object and have it slide across (tween) and stop. Then when the mouse is removed from the object, it returns to its original position.

    Here's an example: http://benpieperphoto.com

    It's fine if we just make it happen to a box - don't worry about all the slideshow bits and all that.

    Thank you!

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try something like this, it incorporates the Tween class within Flash. There are other Tween engines available and can be easily switched. HTH.

    PHP Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    sl.addEventListener(MouseEvent.MOUSE_OVERmOver);
    sl.addEventListener(MouseEvent.MOUSE_OUTmOut);

    function 
    mOver(e:MouseEvent):void {
        var 
    tIn:Tween = new Tween(e.currentTarget"x"Regular.easeOutsl.xsl.75.5true);
    }
    function 
    mOut(e:MouseEvent):void {
        var 
    tOut:Tween = new Tween(e.currentTarget"x"Regular.easeOutsl.xsl.75.5true);

    Wile E. Coyote - "Clear as mud?"

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    thank you

    I'll try it out - thanks a ton!

  4. #4
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Forgot to mention that the above code is in AS3, in case you were wondering.
    Wile E. Coyote - "Clear as mud?"

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Oops

    Yeah, I figured it was AS3. Thanks for the help, but it seems I have grossly overestimated my abilities. What values do I replace with my own object name? Is there a com pack I need to download for the fl import to work? I'm so lost.

  6. #6
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    ok - I did some figuring out myself - thanks for your help so far, I changed the name of my object to sl and it works! The only problem is when the mouse is at the edge of the object, it fluctuates rapidly.

    Example at http://foreverdayphotos.com/fdp2010.html - the blue box.

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    ok - i think i was having a local flash rendering problem. I'll let you know if i still have problems - thanks so much!

  8. #8
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try this to see if it helps.
    PHP Code:
    var startPos:Number sl.x// or use the numeric equivalent to sl.x 
    Then use the variable in the tween parameters, for tIn: sl.x, for tOut: sl.x - 75.
    Wile E. Coyote - "Clear as mud?"

  9. #9
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    As usual, I don't understand. Can you please set me up with some sample code - like the whole set and I'll just sub numbers? Sorry for the hassle, but I really am a n00b.

  10. #10
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try uploading the file and I'll have a look at it.
    Wile E. Coyote - "Clear as mud?"

  11. #11
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    Thanks! Here is is - www.foreverdayphotos.com/fdp2010.fla The blue box is a decoy - feel free to rename it or whatever. The thumbgrid component on the right is what I really want to move in and out. Thanks again!

  12. #12
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    For the thumbgrid, try something like this,
    PHP Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    thumbgrid.addEventListener(MouseEvent.MOUSE_OVERmOver);
    thumbgrid.addEventListener(MouseEvent.MOUSE_OUTmOut);

    function 
    mOver(e:MouseEvent):void {
        var 
    tIn:Tween = new Tween(e.currentTarget"x"Regular.easeOute.currentTarget.xe.currentTarget.150.5true);
    }
    function 
    mOut(e:MouseEvent):void {
        var 
    tOut:Tween = new Tween(e.currentTarget"x"Regular.easeOute.currentTarget.xe.currentTarget.150.5true);

    Wile E. Coyote - "Clear as mud?"

  13. #13
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    Finally got round to trying it out - same exact problem. The thumbgrid component fluctuates rapidly when the mouse if over it.

    www.foreverdayphotos.com/fdp2010.html

    Thanks again for all your help.

    When you reply, please send me a full set of code - I can't figure out where to add / remove exchange snippets.

  14. #14
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try this.
    File Link
    Wile E. Coyote - "Clear as mud?"

  15. #15
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    Thanks again for all your help. Same problem exactly, the object just oscillates and keeps going off the page. Should I give this up? I though it would be simple but it's really turning into a hassle. I hate to keep bothering you.

  16. #16
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Don't know what to tell you... as it works for me just fine.
    Wile E. Coyote - "Clear as mud?"

  17. #17
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try replacing the code with this and see if it works any better.

    PHP Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    thumbgrid.addEventListener(MouseEvent.MOUSE_OVERmOver);
    thumbgrid.addEventListener(MouseEvent.MOUSE_OUTmOut);

    var 
    startPos:Number 931;
    var 
    endPos:Number 831;

    function 
    mOver(e:MouseEvent):void {
        var 
    tIn:Tween = new Tween(e.currentTarget"x"Regular.easeOutstartPosendPos1true);
    }
    function 
    mOut(e:MouseEvent):void {
        var 
    tOut:Tween = new Tween(e.currentTarget"x"Regular.easeOute.currentTarget.xstartPos1true);
        if(
    e.currentTarget.!= startPos) {
            
    e.currentTarget.startPos;
        }
        
    trace(e.currentTarget.x);

    Last edited by Robb@exo; 10-10-2010 at 12:24 AM.
    Wile E. Coyote - "Clear as mud?"

  18. #18
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    Hi,

    Sorry it's been a while. I got pretty dejected and I'm losing hope :-(

    I tried the code you put above, and it's erroring on lines 11 and 14. Syntax error: expecting identifier before var, and Label must be a simple identifier on both.

    Any other help you can give would be appreciated.

    Thank you.

  19. #19
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Take out the "*" in 11 and 14, not sure why they were there in the first place.
    Wile E. Coyote - "Clear as mud?"

  20. #20
    Junior Member
    Join Date
    Sep 2010
    Posts
    19
    Umm, there is no "*" in 11 or 14.

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