# Simple Scripted MC Movement/Easing

**URL:** <https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547>\
**Category:** Uncategorized\
**Created:** [December 10, 2003, 7:00pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547 "2003-12-10T19:00:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![newhopekenny](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/newhopekenny/32/317_2.png) [@newhopekenny](https://forum.kirupa.com/u/newhopekenny)\
**Post date:** [December 10, 2003, 7:00pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/1 "2003-12-10T19:00:19Z")

</div>

Okay, I quit. I’ve tried incrementing \_x, startDrag’s with easing…nothing. Anyone that can help explain how to code the little red bar for the navigation on this site ( [http://www.brandnewrock.com/index.php](http://www.brandnewrock.com/index.php) ) will become my hero.

I’m kind of new, kind of not new…which is why I feel like an \*\*\* posting this question, because I SHOULD KNOW THIS.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2003, 7:05pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/2 "2003-12-10T19:05:15Z")

</div>

```auto

MovieClip.prototype.easeX = function(tX){
this.onEnterFrame = function(){
this._x = tX-(tX-this._x)/1.6;
this._x > tX-1 && this._x < tX+1 ? delete this.onEnterFrame : null
}
}
btn1.onRollOver = btn2.onRollOver = btn3.onRollOver /*...*/ = function(){
redLine.easeX(this._x);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2003, 7:09pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/3 "2003-12-10T19:09:29Z")

</div>

Heh…yea…about ten seconds after posting I checked the Flash MX 2004 forum…and saw your post almost identical to this one.

Thanks a bunch, and I amended the function a bit to set the underline MC’s width equal to the MC it resides under, as well as easing the movement.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2003, 7:45pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/4 "2003-12-10T19:45:48Z")

</div>

Sorry to bother this thread again, but again, I can’t get this to work the way I want it.

How can I set it so that if the mouse is not over the navigation buttons (ie. home, portfolio, etc.) the underline moves away from all navigation buttons (by setting its x equal to -300, for example)?

I used a a function that used hitTests and setIntervals…but the action would still fire (with the appropriate delay a-la setInterval) when the mouse was over the nav MCs.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2003, 8:07pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/5 "2003-12-10T20:07:26Z")

</div>

Oh, and here’s the AS:

On frame one:

```auto
MovieClip.prototype.easeX = function(tX, tWidth) {
	this.onEnterFrame = function() {
		this._x = tX-(tX-this._x)/1.2;
		this._width = tWidth-10;
		this._x>tX-1 && this._x<tX+1 ? delete this.onEnterFrame : null;
	};
};
function easeOff() {
	homeTest = hitTest(home._x, home._y);
	portfolioTest = hitTest(portfolio._x, portfolio._y);
	questionsTest = hitTest(questions._x, questions._y);
	experimentsTest = hitTest(experiments._x, experiments._y);
	employmentTest = hitTest(employment._x, employment._y);
	if (!homeTest && !portfolioTest && !questionsTest && !experimentsTest && !employmentTest) {
		underline.easeX(-300, 46);
		clearInterval(easeInterval);
	}
}
function easeFunction() {
	easeInterval = setInterval(easeOff, 4000);
}
home.onRollOver = portfolio.onRollOver=questions.onRollOver=experiments.onRollOver=employment.onRollOver=function () {
	this.gotoAndPlay("mouseOver");
	underline.easeX(this._x, this._width);
};
home.onRollOut = portfolio.onRollOut=questions.onRollOut=experiments.onRollOut=employment.onRollOut=function () {
	this.gotoAndPlay("mouseOut");
	easeFunction();
};

```

The code works fine for a few rollOver’s…but then it starts to act screwy. Any help?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2003, 8:20pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/6 "2003-12-10T20:20:24Z")

</div>

Using trace, I found that the main problem is that the setInterval keeps getting called every four seconds, instead of just being called once and clearing by way of the easeOff() function. Any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 11, 2003, 10:39pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/7 "2003-12-11T22:39:45Z")

</div>

How can I get it to stop calling the setInterval? I have the clearInterval…but it doesn’t work…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2003, 5:56pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/8 "2003-12-12T17:56:48Z")

</div>

Anyone? Please? I can offer my first born as payment. :pir:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2003, 8:15pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/9 "2003-12-12T20:15:11Z")

</div>

Well, here’s a sample FLA:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2003, 8:52pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/10 "2003-12-12T20:52:06Z")

</div>

Try this:

```auto

MovieClip.prototype.easeX = function(tX){
        this.onEnterFrame = function(){
                this._x = tX-(tX-this._x)/1.6;
                this._x > tX-1 && this._x < tX+1 ? delete this.onEnterFrame : null
        }
}
easAway = function(){
redLine.easeX(-300);
clearInterval(wait);
}
btn1.onRollOver = btn2.onRollOver = btn3.onRollOver /*...*/ function(){
        redLine.easeX(this._x);
}
btn1.onRollOut = btn2.onRollOut = btn3.onRollOut /*...*/ function(){
wait = setInterval(easeAway,2000)
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2003, 1:51am UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/11 "2003-12-13T01:51:51Z")

</div>

That exactly what I’m trying, and it works…except that it doesn’t clear the setInterval and keeps calling it over and over (and multiple times, for each rollOut call).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2003, 6:15pm UTC](https://forum.kirupa.com/t/simple-scripted-mc-movement-easing/96547/12 "2003-12-13T18:15:40Z")

</div>

Try :

```auto

MovieClip.prototype.easeX = function(tX){
        this.onEnterFrame = function(){
                this._x = tX-(tX-this._x)/1.6;
                this._x > tX-1 && this._x < tX+1 ? delete this.onEnterFrame : null
        }
}
easAway = function(){
        redLine.easeX(-300);
        clearInterval(_root.wait);
}
btn1.onRollOver = btn2.onRollOver = btn3.onRollOver /*...*/function(){
        redLine.easeX(this._x);
}
btn1.onRollOut = btn2.onRollOut = btn3.onRollOut /*...*/function(){
        _root.wait = setInterval(easeAway,2000)
}

```
