# Change direction of movie clip/stopping moving clip

**URL:** <https://forum.kirupa.com/t/change-direction-of-movie-clip-stopping-moving-clip/255174>\
**Category:** Uncategorized\
**Created:** [March 19, 2008, 7:04pm UTC](https://forum.kirupa.com/t/change-direction-of-movie-clip-stopping-moving-clip/255174 "2008-03-19T19:04:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisaom](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@chrisaom](https://forum.kirupa.com/u/chrisaom)\
**Post date:** [March 19, 2008, 7:04pm UTC](https://forum.kirupa.com/t/change-direction-of-movie-clip-stopping-moving-clip/255174/1 "2008-03-19T19:04:18Z")

</div>

Hello everyone,  
I cannot wrap my brain around this anymore. It’s been sometime since I have done much actionscript but here it is:

**Functionality:**  
I have the movie clip moving from left to right and once it reaches a certain point, it changes direction and goes back, infinitely.

I have a hitTest to check weather the mouse is over the target movie clip, if it is, the movement stops.

\*\*  
Problem1 - Movement:  
\*\*When I mouseover the target movie clip it stops (hitTest=true) but the movement does not resume when the hitTest is false.

\*\*Here’s the code:  
\*_var xchange=10;  
holder\_mc.onEnterFrame = function() {  
//trace("x\_pos: "+this.\_x)  
//trace("xchange: "+xchange)  
this.\_x += xchange;  
if (this.hitTest(\_xmouse, \_ymouse, true)) {  
xchange=0;  
this.\_x += xchange;  
}  
else{  
if(this.\_x \> 0){  
xchange=10;  
xchange_= -1;  
}  
else if(this.\_x \< -645){  
xchange \*= -1;  
}  
}  
}//--------------------------------------  
\*\*Problem 2 - CPU Resources \*\*  
Also I have code on the individual movie clips within the target movie clip, they simply play frames forward and backward to enlarge a thumbnail. After a while the computer starts hating life and chugs. I know it is from the hitTest checking on each enterFrame and it eats up the resources. Is there a way to do this without the chug?

Here is the code that expands the thumbnails within the target movie clip:

stop();  
this.onEnterFrame = function() {  
if (rewind == true) {  
prevFrame();  
}  
};  
this.onRollOver = function() {  
this.swapDepths(this.getNextHighestDepth());  
rewind = false;  
play();  
};  
this.onRollOut = function() {  
rewind = true;  
};

//----------------------

If someone could give me any insight into this problem I would greatly appreciate it.  
Thanks guys,  
I hope I’ve been clear.
