A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [AS2] fade in + out of clip

  1. #1
    Member
    Join Date
    Feb 2005
    Posts
    81

    [AS2] fade in + out of clip

    Hi all,
    I have the following functions that fade a movie clip in and out

    Code:
    fadeAmount = 1;
    function fadeIn() {
    	this._alpha += fadeAmount;
    	if (this._alpha>=100) {
    		this._alpha = 100;
    		this.onEnterFrame = null;
    	}
    }
    function fadeOut() {
    	this._alpha -= fadeAmount;
    	if (this._alpha<=0) {
    		this._alpha = 0;
    		this.onEnterFrame = null;
    	}
    }
    and then I call the movie clip to start fading in and appear on stage

    Code:
    contentMC._alpha = 0;
    contentMC.onEnterFrame = fadeIn;
    what I need is some way to tell the movie "after you reach alpha 100, stay there for x seconds and then fade out" and execute this code:

    Code:
    contentMC._alpha = 100;
    contentMC.onEnterFrame = fadeOut;
    after it reaches alpha = 0 it should stop and stay there without looping back and starting to fade in again. Thanks.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    call fadeOut() in a setInterval() after the this.onEnterFrame = null;. And clear the setInterval inside the fadeOut() function.
    In case, more info about setInterval in the liveDocs (link in my footer)
    gparis

  3. #3
    Member
    Join Date
    Feb 2005
    Posts
    81
    hmmmm, I see what you mean, have setInterval count x milliseconds and then call the fade out from then on. Am I close to that somehow (my noobish skills must be botching the syntax...)?

    Code:
    fadeAmount = 1;
    function fadeIn() {
    	this._alpha += fadeAmount;
    	if (this._alpha>=100) {
    		this._alpha = 100;
    		this.onEnterFrame = null;
    		myInterval = setInterval(this, 5000);
    		if (myInterval>=5000) {
    			function fadeOut() {
    				this._alpha -= fadeAmount;
    				if (this._alpha<=0) {
    					this._alpha = 0;
    					this.onEnterFrame = null;
    				}
    			}
    		}
    	}
    }
    Last edited by mx_green; 04-22-2010 at 02:13 PM.

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