Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    876
    Thanks
    53
    Thanked 6 Times in 5 Posts

    actionscript for image slider

    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?:

    Code:
    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;
    }
    gotoAndPlay(2);
    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;

    http://aapress.com.au/demo/slider.html
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    New Coder
    Join Date
    Jan 2012
    Location
    Columbus, Ohio, U.S.A
    Posts
    41
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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.

    -Adam

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    876
    Thanks
    53
    Thanked 6 Times in 5 Posts
    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.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #4
    New Coder
    Join Date
    Jan 2012
    Location
    Columbus, Ohio, U.S.A
    Posts
    41
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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..
    Code:
    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
    {
                while(!currentlyHovering)
                 {
                      //do your thing and call your perpetual hover code
                      perpetuallyHover();
    
                  }
    
    }
    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.

    -Adam

  • #5
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    876
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Always grateful for a reply!

    I added this to the timeline:

    Code:
    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?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #6
    New Coder
    Join Date
    Jan 2012
    Location
    Columbus, Ohio, U.S.A
    Posts
    41
    Thanks
    0
    Thanked 8 Times in 8 Posts
    hi,

    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?
    Code:
    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.

  • #7
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    876
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Thanks adaminaudio.

    I could be putting it in the wrong place too.

    http://aapress.com.au/PRD/USM1.fla
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #8
    New Coder
    Join Date
    Jan 2012
    Location
    Columbus, Ohio, U.S.A
    Posts
    41
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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

  • #9
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #10
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you have your imagecontainer or whatever, add a boolean and some listeners..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •