# IMAGE: Idle Scroll

**URL:** <https://forum.kirupa.com/t/image-idle-scroll/57587>\
**Category:** flash\
**Created:** [July 14, 2004, 2:19pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587 "2004-07-14T14:19:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SmileyGladhand](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@SmileyGladhand](https://forum.kirupa.com/u/SmileyGladhand)\
**Post date:** [July 14, 2004, 2:19pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587/1 "2004-07-14T14:19:53Z")

</div>

Hi,

I’m using the following code to continuously scroll an image. I want to keep the mouseover but I need a way to make it scroll at an idle speed when the mouse isn’t over the image. I’d greatly appreciate any help.

```
 onClipEvent (load)
 {
 mouseOn = false;
 xcenter=600;
 speed=1/10;
 }
 
 on(rollOver)
 {
 mouseOn = true;
 }
 
 on(rollOut)
 {
 mouseOn = false;
 }
 
 onClipEvent (enterFrame)
 {
 if(mouseOn)
 {
 var distance=_root._xmouse-xcenter;
 _x+=(distance*speed);
 if (_x &gt; 0) _x=-1950;
 if (_x &lt; -1950) _x=0;
 }
 }

```

I also noticed the image jumps to the left when the mouse is over it. Any ideas on that?

```
 Thanks
```

---

<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:** [July 14, 2004, 3:10pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587/2 "2004-07-14T15:10:05Z")

</div>

You can’t have on() events inside a MovieClip. Try this code:

```auto
onClipEvent (load) {
mouseOn = false;
xcenter=600;
speed=1/10;
}

onClipEvent (enterFrame) {
if(hitTest(_root._xmouse, _root._ymouse, true)) {
var distance=_root._xmouse-xcenter;
_x+=(distance*speed);
if (_x > 0) _x=-1950;
if (_x < -1950) _x=0;
} else {
//do your idle thang
}
}

```

---

<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:** [July 14, 2004, 3:16pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587/3 "2004-07-14T15:16:14Z")

</div>

do you know the code so it still idles when the mouse isn’t over the image?

---

<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:** [July 14, 2004, 6:47pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587/4 "2004-07-14T18:47:50Z")

</div>

> [@SmileyGladhand](#):
>
> do you know the code so it still idles when the mouse isn’t over the image?

well, when the mouse isn’t over the object, the motion stops. Where I put “//do your idle thang” you insert the code that you want to run when the mouse isn’t over the object. I’ll leave that to you.

---

<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:** [July 14, 2004, 6:55pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587/5 "2004-07-14T18:55:25Z")

</div>

ok… I am new to flash  
Thank you for your help by the way.

I’m using a mask on the image. With your code the image scrolls as long as it’s on the image’s Y axis. The first code only scrolls when the mouse is on the masked part of the image (or would the part of the image you can see be the unmasked?) Have any idea how I can get that with your code?

---

<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:** [July 16, 2004, 1:54pm UTC](https://forum.kirupa.com/t/image-idle-scroll/57587/6 "2004-07-16T13:54:52Z")

</div>

I think I figured it out. Does this look right to you?:

onClipEvent (load) {  
mouseOn = false;  
xcenter=600;  
speed=1/10;  
}

onClipEvent (enterFrame) {  
if(hitTest(\_root.\_xmouse, \_root.\_ymouse, true)) {  
var distance=\_root.\_xmouse-xcenter;  
\_x+=(distance\*speed);  
if (\_x \> 0) \_x=-1950;  
if (\_x \< -1950) \_x=0;  
} else {  
//onClipEvent (enterFrame) {  
\_x -= 5;  
if (\_x\<-1950) {  
\_x = 0;  
}  
}  
}
