dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Easy question for you experts

  1. #1
    Junior Member
    Join Date
    Apr 2002
    Posts
    5

    Angry

    Calling all Flash-Gurus,

    I have an object (movieclip) following my mouse. I would like to have the object go to a specific frame when the mouse pointer is to the left of the object, and a different frame when the mouse pointer is to the right of the object. So the object is always facing the pointer as it follows it. The object only needs to face right or left, not up or down. I'm sure this is an easy one for you.

    Could someone help me with the actionscript for this?
    Thanks for your time!


    PrickleyPete

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    break the movieclip into 2 movieclips. then use hitTest() for the goto frame.
    gparis

  3. #3
    Junior Member
    Join Date
    Sep 2000
    Posts
    18
    depending on how the clip moves, use either on enterframe or on mouse move in the clip. set a variable to the movie clips _x point using localToGlobal, and compare with _root._xmouse.

    if xmouse is greater, the clip will point right towards the mouse, else it should point left.

  4. #4
    Junior Member
    Join Date
    Apr 2002
    Posts
    5
    I'm still having a little bit of trouble implementing the code. Here is the existing code that has the object following the mouse pointer.

    onClipEvent (enterFrame) {
    //x movement
    mx=_root._xmouse;
    if (mx<_x) {
    dx=_x-mx;
    }
    else {
    dx=mx-_x;
    }
    moveSpeedx=dx/30;
    if (mx<_x) {
    _x=_x-moveSpeedx;
    }
    else {
    _x=_x+moveSpeedx;
    }
    //y movement
    my=_root._ymouse;
    if (my<_y) {
    dy=_y-my;
    }
    else {
    dy=my-_y;
    }
    moveSpeedy=dy/30;
    if (my<_y) {
    _y=_y-moveSpeedy;
    }
    else {
    _y=_y+moveSpeedy;
    }
    }


    Do I start a new line of code or can the new coding be put in there somewhere?

    Thanks for you help so far!

    PP

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