|
-
MC follow mouse click
So I'm trying to do something incredibly simple and It just isn't working properly. I'm annoyed at myself for not being able to find a solution but I need a fresh head on it!
Imagine we have a MovieClip called "box". When I click somewhere on the screen, I want the box MC to move to that position. So I wrote something like this (just for horizontal movement):
PHP Code:
onMouseDown=function(){ moveTo(_xmouse); };
function moveTo(newx){ box.onEnterFrame=function(){ if(box._x<newx){ box._x+=5; }else if(box._x>newx){ box._x-=5; }else{ delete box.onEnterFrame; } }; }
Now this works to a degree, except that when the box MC moves to the right position, it then proceeds to vibrate on the spot. I thought it was probably because it can never move to the exact position of _xmouse because I'm adding 10 to the x property which is why the condition is never met. However even if I just add 1 instead of 10, I still have the same problem..
Any ideas before I go mad?
Last edited by lightspeed10; 02-15-2010 at 06:36 PM.
-
Senior Member
Try something like this,...
Actionscript Code:
import mx.transitions.Tween; import mx.transitions.easing.*;
_root.onMouseDown = function() { var tx:Object = new Tween(box, "_x", Regular.easeOut, box._x, _xmouse, 1, true); var ty:Object = new Tween(box, "_y", Regular.easeOut, box._y, _ymouse, 1, true); }
Wile E. Coyote - "Clear as mud?"
-
I thought about using the tween class, but didn't know if it would be the most efficient way.
I gave it a go, and it returned this beastly error! :\
Code:
**Error** C:\Documents and Settings\Chris\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes\mx\transitions\Tween.as: Line 15: There is no method with the name 'OnEnterFrameBeacon'.
static var __initBeacon = OnEnterFrameBeacon.init();
**Error** C:\Documents and Settings\Chris\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes\mx\transitions\Tween.as: Line 16: There is no method with the name 'BroadcasterMX'.
static var __initBroadcaster = BroadcasterMX.initialize (Tween.prototype, true);
**Error** C:\Documents and Settings\Chris\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes\mx\transitions\Tween.as: Line 148: There is no method with the name 'OnEnterFrameBeacon'.
OnEnterFrameBeacon.init();
-
No worries, sorted it! Wrote a tween script from scratch.. and it worked :\
Code:
function walkTo(newX, newY) {
var xMove:Object = new Tween(girl, "_x", Regular.easeOut, girl._x, newX, 10, UseSeconds);
xMove.onMotionFinished = function() {
var yMove:Object = new Tween(girl, "_y", Regular.easeOut, girl._y, newY, 10, UseSeconds);
};
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|