A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Fade alpha of Movie Clip

  1. #1
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29

    Fade alpha of Movie Clip

    Greets all,

    I'm trying to do some actionscript that will fade the alpha value of a movie clip (which contains a video). Right now my mouse events only set the alpha to 100% and 0%.


    mcVideo._alpha = 0;

    mcContainer.onPress = function():Void {
    this.mcVideo._alpha = 100;
    };

    mcContainer.onRelease = function():Void {
    this.mcVideo._alpha = 0;
    };



    This is cool and works well but it would be nice to have a fade. How would I do this? Thanks in advance!

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    either you use a function (with a loop like setInterval or enterFrame) or the Tween Class. Check the liveDocs for the latest (link in my footer). In case you don't know how to write a function, do a simple search in this forum with keywrods alpha and fade.

    gparis

  3. #3
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    I've been trying to call a function on an Interval. Only problem is, it doesn't seem to work and I don't know why.


    mcVideo._alpha = 0;
    var nInterval:Number;


    mcContainer.onPress = function():Void {
    nInterval = setInterval(fadeVideo, 50, mcVideo);
    };

    mcContainer.onRelease = function():Void {
    this.mcVideo._alpha = 0;
    };


    function fadeVideo(mcVideoFade:MovieClip):Void {
    mcVideoFade._alpha += 10;
    }

  4. #4
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Just thought I'd mention, what I'm attempting to do is fade mcVideo slowly from 0 to 100 when when mcContainer is pressed. And have it go immediately back to 0 when mcContainer is released.

  5. #5
    Member
    Join Date
    Jun 2007
    Posts
    36
    the problem is when you create the nInterval object, you're specifying it as a number(var nInterval:Number). take out ":Number" and it should work.

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    both movies sit on the same timeline? if yes your shouldn't say: this.mcVideo in the other mc's handler.

    gparis

  7. #7
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    By doing some digging and searching I've replaced the previous code with:


    mcMovie._alpha = 0;

    mcButton.onPress = function() {
    mcMovie.onEnterFrame = function() {
    mcMovie._alpha += 10;
    }
    }
    mcButton.onRelease = function() {
    mcMovie.onEnterFrame = function() {
    mcMovie._alpha -= 20;
    }
    }


    This is on frame one of the actions layer. It seems to work but it is also unpredictable. About the only time it does exactly what it's supposed to do is the first time I press and release mcButton. mcMovie fades in and fades out perfectly and in perfect coincidence with the press and release of mcButton. After that it becomes more random. For example when I press mcButton again it may take a while for mcMovie to begin to fade in. And after releasing mcButton it may take some time for it to fade out, and the times seem to be radically different with each press/release of mcButton. Moreover, if I hold mcButton for a length of time, say 5 seconds or more, it takes a very long time for mcMovie to fade out again upon release of mcButton.

    One other thing seems to be that once mcMovie has run its course once, then the fade in/out function no longer works at all. I have searched through the archives but cannot readily find an answer to this problem. Does anyone know what may be causing this behavior?

  8. #8
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Quote Originally Posted by gparis
    both movies sit on the same timeline? if yes your shouldn't say: this.mcVideo in the other mc's handler.
    One movie is an FLV that is progressively download from a server and has it's own FLVplayback component (no skin or controls). mcMovie (the one I'm fading) is an imported video that is on its own timeline in the Movie Clip mcMovie. mcMovie is place on its own layer about the FLV video. When I press mcButton the intended result is to bring the alpha of mcMovie to 100, covering and playing over top of the FLV video only for the time that mcButton is pressed.

  9. #9
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    You need some conditionnal so that once _alpha is 100 or 0, the loop stops, so you don't go "above and beyond"

    PHP Code:
    mcMovie._alpha 0;
    mcButton.onPress = function() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha 100?this._alpha+= 10:delete this.onEnterFrame;
        };
    };
    mcButton.onRelease = function() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha 0?this._alpha-= 20:delete this.onEnterFrame;
        };
    }; 
    gparis

  10. #10
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Quote Originally Posted by gparis
    You need some conditionnal so that once _alpha is 100 or 0, the loop stops, so you don't go "above and beyond"

    PHP Code:
    mcMovie._alpha 0;
    mcButton.onPress = function() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha 100?this._alpha+= 10:delete this.onEnterFrame;
        };
    };
    mcButton.onRelease = function() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha 0?this._alpha-= 20:delete this.onEnterFrame;
        };
    }; 
    gparis

    Works poifect.. Thank you!

    So essentially the 'delete this.onEnterFrame' is clearing the function once the alpha reaches 100, and visa versa? I know I ask a lot of questions but I like to learn and understand what I've done

  11. #11
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    is deleting the loop, yes.
    gparis

  12. #12
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    I realized there are some who will only "click" the button (because that's what they're programmed to do with Flash buttons) rather than pressing and holding the button, thereby opening the possibility of them thinking nothing is happening. I rearranged things a bit and added a bit of code to the onPress event calling function alphaUp, in order that the MovieClip doing the fading will become visible enough to denote something taking place, regardless of the "quickness" of the click. (Also added a text element that becomes _visible onPress and visa versa).


    PHP Code:
    mcMovie._alpha 0;
    mcText._visible false;
    mcButton.onPress = function() {
        
    alphaUp();
    };
    mcButton.onRelease = function() {
        
    setTimeout(alphaDown1000);
    };
    function 
    alphaUp() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha<100 this._alpha += 10 delete this.onEnterFrame;
            
    mcText._visible true;
        };
    }
    function 
    alphaDown() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha>this._alpha -= 20 delete this.onEnterFrame;
            
    mcText._visible false;
        };

    Last edited by FlashKit#C5; 01-01-2008 at 09:15 AM.

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