A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: setInterval and Alpha fade

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    3

    setInterval and Alpha fade

    only recently started using action script and i have hit a wall of sorts.
    on my brief research i have managed to put together the code:

    onClipEvent(load){
    this._alpha = 0;
    }
    onClipEvent(enterFrame){
    setInterval(function(mc){
    if(mc._alpha<100){
    mc._alpha += 3;
    }
    clearInterval();
    }
    ,2000, this);

    setInterval(function(mc2){
    if(mc2._alpha>0){
    mc2._alpha -= 10;
    }
    clearInterval();
    }
    ,5000, this);
    }

    this gets my mc to fade in, wait, then fade out. however once the alpha gets back to 0 the two if loops conflict an my mc starts flickering.
    can anyone help me out with a solution.
    thanks in advance.

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Well you're using setInterval and enterFrame, you should really only need one or the other. Second, to clear an interval you need to assign it a name when you set it. It also appears that you're trying to fade in over about 60 seconds and fade out over 30 seconds.

    So let's be clear on what you want to do...this is a single movie clip that you want to fade in, wait, and then fade out, correct? How long do you want each step to take?

  3. #3
    Junior Member
    Join Date
    Jun 2006
    Posts
    3
    thanks for the reply.
    currently the clip fades in over about 3 seconds.
    i want the mc to wait 4 seconds and then fade out.
    the fade out should take 3 seconds also.

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    You could probably use the built in Tween functions, but I'm less familiar with them. Try this on the main timeline. I used a clip with an instance name of "box"

    Code:
    function fadeIn() {
    	if (box._alpha<100) {
    		box._alpha += 1;
    	} else {
    		clearInterval(fadeInterval);
    		setTimeout(startOut, 4000);
    	}
    }
    function fadeOut() {
    	if (box._alpha>0) {
    		box._alpha -= 1;
    	} else {
    		clearInterval(fadeInterval);
    	}
    }
    function startOut() {
    	fadeInterval = setInterval(fadeOut, 30);
    }
    box._alpha = 0;
    var fadeInterval = setInterval(fadeIn, 30);

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