A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: setInterval in a Button

  1. #1
    Buttnutsford Jon Roobottom's Avatar
    Join Date
    Mar 2000
    Location
    Brownhills UK
    Posts
    98

    setInterval in a Button

    yo yo,

    I have a set interval on a button like this....

    Code:
    on (rollOver) {
    	fadeOutAction = setInterval(_root.fadeOut('quality'), 10);
    }

    the function it calls fades the target mc out... Unfortunatly when I roll over the button, the setInterval is only executed once, and not over and over every 10mS like it should.

    I know it's nothing to do with the fucnction, as calling the setInterval from anywhere else produces the right results.

    Anyone else experianced this problem or know how to fix it?


    Cheers!!

  2. #2
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    What is your code for the set interval function as the rollover method should work fine?
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  3. #3
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    I know what you have done, you have not used the object interval method.....

    Code:
    // replace your function to be executed with this...
    fadeOut = new Object();
    fadeOut.interval = function(qualityVar) { 
        // insert your current functions code in here!
    
    }
    
    // the code on your button is...
    on (rollOver) {
    	fadeOutAction = setInterval(_root.fadeOut,"interval", 10, quality);
    }
    ** edited to be named more like what you are using already
    *** error corrected is in bold
    Last edited by Lexicon; 06-28-2004 at 08:12 AM.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  4. #4
    Buttnutsford Jon Roobottom's Avatar
    Join Date
    Mar 2000
    Location
    Brownhills UK
    Posts
    98
    interval? is that mx 2004?

    i'm using mx...

    Just been looking at your site... very nice! Like the artwork.

  5. #5
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    thanks Jon,

    it should work fine in MX, its all AS1.

    A side note though, if you roll over your mouse, roll out and then roll over again before the first set interval has completed, then you will get 2 instances of the same set interval function being run.
    So you will probably want to set a variable somewhere to determine whether the set interval function is already running or not before executing it.

    e.g.
    Code:
    // where buttonMC is the movieclip containg the button
    
    fadeOut = new Object();
    fadeOut.interval = function(qualityVar) { 
        stopInterval = true;
        buttonMC._alpha-=10;
        if (buttonMC._alpha == 0)
            clearInterval(buttonMC.fadeOutAction);
            stopInterval = false;
        }
    }
    
    // the code on your button is...
    on (rollOver) {
        if (!_root.stopInterval){
    	fadeOutAction = setInterval(_root.fadeOut,"interval", 10, quality);
        }
    }
    Please note that there was a mistake in the code I posted in previous post. the line should have read.

    fadeOutAction = setInterval(_root.fadeOut,"interval", 10, quality);
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  6. #6
    Buttnutsford Jon Roobottom's Avatar
    Join Date
    Mar 2000
    Location
    Brownhills UK
    Posts
    98
    yeah, this worked a treat! cheers!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center