Skip to main content
Participant
October 28, 2010
Question

[CS4 or CS5] How to change frame of movieclip depending on relation to mouse

  • October 28, 2010
  • 1 reply
  • 400 views

I have a movie clip that follows the mouse..

Its not done yet but its gonna be a dog chasing a/the mouse...

I want to have it where the if the mouse is left or right of the following movie clip it shows it walking toward the mouse... so something like

if mouse positions is less the the cursor + 10 (pixels) goto and play frame with dog walking left

and one for right
up
down
(I want this to walk till its directly under or over mouse and then laydown or jump only when over or under mouse.. IS THAT POSSIBLE?? )


(say its a 20 pixel wide object and 10 on each side will cover the whole thing and not just the exact center pixel, thats what the 10 + movie clip position is for, but Is there a way to tell it to goto and play whatever_frame when mouse is left of any graphic on the sitting dog section???
like the equivalent of onRollLeft or whatever.)

this is the code i have..
its the top statement that doesn't work the bottom 2 do..

Code

if (_xmouse < detail.x+10) {detail.gotoAndPlay(61);

}

detail.onRollOver = function() {
detail.gotoAndPlay(31);
}

detail.onRollOut =function(){
detail.gotoAndPlay(1);
}

I dont have all the animations made so if you know how to do this just do it with a shape like i did in frame 61 of the instance "detail" of the movieclip "dog"

if i cover all directions i shouldn't need the last one- onRollOut.

really what im asking for if you havent figured it out by now is to help me with the actionscript that will do what i did with the rollover and rollout, but put

1 (a shape of a different color in a frame in the clip dog) when mouse is any left of dog
2 (a shape of a different color in a frame in the clip dog) a shape of a different color when mouse is any right of dog
3 (a shape of a different color in a frame in the clip dog) a shape of a different color when mouse is directly under dog
4 (a shape of a different color in a frame in the clip dog) a shape of a different color when mouse is directly above dog

I already created the shapes and placed them in the appropriate frames..
you should only need to mess with the actions on the instance "detail" (the dog face in frame 1 of scene 1 in layer "follower"

my fla is to big to upload to this form so im placing it on my website
here

This topic has been closed for replies.

1 reply

Participant
October 28, 2010

Hello utcpunk201,

I have edited your FLA but can't send you the file in this forum as there is no such option to upload FLA files here. I am giving you a brief detail what I have done with your file.

1. Just remove your frame script

2. Edit your script what you wrote on your MovieClip (instance name: detail). Use the script I am sending you below:

Script :

onClipEvent (load) {
    _x = 0;

    speed = 15;
    ymov = false;
}
onClipEvent (enterFrame) {
    endX = _root._xmouse;
    endY = _root._ymouse;
    _x += (endX - _x) / speed;
    _y += (endY - _y) / speed;


    if (_root._xmouse > this._x + 20)
    {
        this.gotoAndStop(90);


    }
    else if (_root._xmouse < this._x - 20)
    {
        this.gotoAndStop(61);


    }else{
        ymov = true;
    }

    if (_root._ymouse > this._y && ymov == true)
    {
        this.gotoAndStop(120);

    }
    else if (_root._ymouse < this._y && ymov == true)
    {
        this.gotoAndStop(150);

    }


}

3. Change the dog movieclip name with detailmc

4. Use a small line in your dog movieclip's frame number 61, 90, 120 and 150. Write down this line : _root.detailmc.ymov = false;

Now export your Flash file. It will work. I can send you the edited file if you can give me your email ID.

Thanks

Amitava D

Participant
October 28, 2010

kinda works but:

the confetti on mouse over doesn't work

and up and down work but not ONLY when directly under or above..

right and left dont work at all

the syntax is probably some right but how do you say

if x is greater than movie-clip-position + 15 goto and play [1]

if x is less than movie-clip-position - 15 goto play [2]

if above and less than movie-clip-position - 15 goto and play [3]

if above and greater than  movie-clip-position +15 goto and play [3]

if below and less than movie-clip-position - 15 goto and play [4]

if below and greater than  movie-clip-position +15 goto and play [4]

if inside of the 30 pixel square in the middle that is left goto and play [5]

[this being a frame number]

you dont have to give me the completed file or even actionscript that correctly calls the frames from the instance "detail"

just the actionscript with general (instance-name) and [frame-number] substitution

but if you want to be my guest... if you can't upload the file (saving as CS4 greatly reduces file size) just message me privately and I'll give you my email..

Participant
October 28, 2010

remember movie clip should also follow mouse (only on x but if you give me both i can figure out how to delete y)...