View Full Version : actionscript for image slider

06-20-2012, 08:02 AM
This actionscript for a flash image slider works reasonably well, but I am wondering if it can be slowed down. At the moment it positively races the image across the screen on load. Which part controls the speed?:

mouseX = _xmouse;
menuX = menu._x;
if (mouseX>480) {
diff = (mouseX-480)/15;
if (mouseX<420) {
diff = (420-mouseX)/15;
if (mouseX<=450 && menuX<=850) {
setProperty("menu", _x, menuX+diff);
if (mouseX>=450 && menuX>=-600) {
setProperty("menu", _x, menuX-diff);
if (menu._x>=850) {
menu._x = 850;
} else if (menu._x<=-600) {
menu._x = -600;

Also, can it be made to slide the image back and forth perpetually until a hover?

Here's a demo of how it is at present;


06-20-2012, 02:31 PM
have you tried messing with the Frames Per Second (fps) setting?

It should be in your properties toolbar somewhere. It could be in the high 30's or something and that could be part of the reason it is going so rapidly.

As far as a perpetual thing. You could use an EnterFrame event and keep looking for a mouse hover or you can place all your images in a container (like a sprite), add a mouseover listener and then use a boolean or something to stop it. Not terribly difficult and a few ways to do it, it just takes some expirementation.

I hope I've helped.


06-20-2012, 03:26 PM
Thanks Adam. The fps was 24 but if I make it any lower it becomes jerky. So perversely I made it 30 which solved the jerkiness.

...then I changed the divisor in lines 4 and 7 from 15 to 200.

Just a shot in the dark, but it worked.

I don't really know how to do the perpetual back and forth thing using your suggestions, but thanks anyway. I'll play around with it.

06-20-2012, 05:04 PM
yeah, sorry. It's highly possible that I'm confused (it happens ) :)

but for example -->

//you have your imagecontainer or whatever, add a boolean and some listeners..

var currentlyHovering:Boolean = false;

imageContainer.addEventListener(MouseEvent.MOUSE_OVER, function(){
currentlyHovering = true;

imageContainer.addEventListener(MouseEvent.MOUSE_OUT, function(){
currentlyHovering = false;

//and you can have an enter frame event on the app...
this.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);

function onEnterFrame(event:Event):void
//do your thing and call your perpetual hover code



something like that maybe, I'm just going off the top of my head here and trying to help out is all.

Again, all apologies if I'm not fully understanding what you're trying to do.


06-21-2012, 11:59 AM
Always grateful for a reply!

I added this to the timeline:

onClipEvent(load) {
speed = 5;
onClipEvent(enterFrame) {
this._x += speed;
if ( this._x > 850 ) this._x = 0;

It makes it scroll to the left and when it gets all the way, it instantly flicks back to the far right and starts again.

So how might I make it get to far left and then scroll nicely back to far right and start again?

06-22-2012, 02:19 AM

I'm just kinda guessing on this one, post your .fla if you have it. but have you tried playing around with a negative speed at all?

onClipEvent(enterFrame) {

if ( this._x > 850 ){
speed = -5;

else if(this._x <=0){
speed = 5;
this._x += speed;


again, just taking a stab hoping to keep your post alive in case anybody has more efficient solutions for you.

06-22-2012, 03:11 AM
Thanks adaminaudio.

I could be putting it in the wrong place too.


06-22-2012, 04:49 AM
hi Tpeck,

take this post if you can and bring it to the guys on Actionscript.org and put it in the AS2 forums.

I'm not as well versed in AS2 as I am AS3 and they've got some swedes over there that've been doing this for years and will probably have your solution up to you in no time (and may give you a few AS2 pointers that I certainly don't know about).

I thought I had more time to look at this but I won't be able to get to it for awhile. They have guys over there that are on all night lol :)

06-24-2012, 04:50 PM
DWI Lawyer Brooklyn (http://www.robertgershon.com)

06-28-2012, 07:41 AM
you have your imagecontainer or whatever, add a boolean and some listeners..