Skip to main content
Participating Frequently
November 15, 2010
Answered

Help! I need this movieclip to follow the cursor but only within certain coordinates!

  • November 15, 2010
  • 1 reply
  • 1418 views

Hello

I'm rather new to action scripting and need a bit of a shove in the right direction.

This is what I'm having trouble with - I've used this code to make the background movieclip follow the cursor:

onClipEvent(enterFrame) {
x=_root._xmouse
y=_root._ymouse
_x+=(x-_x)/10
_y+=(y-_y)/10
}

However - I want to restict it's movement so it remains masked behind the other black dot with the "hglf" graphic.

Hope this makes sense and someone can help me out!

Thanks

This topic has been closed for replies.
Correct answer Ned Murphy

oop... only just saw this as I was composing my last answer!

So should I just change the button to a movieclip? If so that still doesn't seem to do it!

And no - don't apologies! I'm really grateful for all your help!


Are you assigning the instance names in the properties panel or are you using the library names?

1 reply

Ned Murphy
Legend
November 15, 2010

You can build a conditional into the code that tests if the mouse is still within the boundaries you want to set.  Maybe something like...

onClipEvent(enterFrame) {
     x=_root._xmouse
     y=_root._ymouse

     if(x > lowerXLimit && x < upperXLimit && y > lowerYLimit && y < upperYLimit){
         _x+=(x-_x)/10
         _y+=(y-_y)/10

     }
}

dirkbangAuthor
Participating Frequently
November 15, 2010

Thanks Ned

Stupid question: where do I set the lowerXlimit etc? Could you highlight the areas?

Ned Murphy
Legend
November 15, 2010

You could set them in the _root timeline and use the _root reference if need be in the conditional.