Skip to main content
Inspiring
Jul 1, 2024 8:31 PM UTC
Answered

Fade up/out MovieClip

I have a simple scene with multiple buttons that each start a different video. Each video lives on a separate frame. Click a button, and it goes to the salient frame and the video plays. What I'd like to do is have the video fade up, play, then fade out. I don't know how to do this. Each button click goes to the frame where it's video lives. 

 

The first frame has all of the actions. They take the following form:

 

this.scarcity_btn.addEventListener("click", fl_ClickToGoToAndStopAtFrame_6.bind(this));
function fl_ClickToGoToAndStopAtFrame_6()
{
this.gotoAndStop(5);
}
 
At each frame where a particular video lives, there's:
this.stop();
 
Since mp4's dont' support alpha channels, I can't do the fading in/out in the video file itself. 
 
Any help would be appreciated.
    This topic is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Jul 2, 2024 12:29 PM UTC

    Hi.

     

    Video components wrap DOM elements, so you'll need CSS for it.

     

    You can add the styles in the HTML file using a publish template or use the .animate method in JavaScript, for example.

    var root = this;
    
    // the two methods below could live in the first frame
    root.onDrawEnd = function(e, data)
    {
        root.fadeVideo(data.id, data.from, data.to, data.duration);
    };
    
    root.fadeVideo = function(id, from, to, duration)
    {
        currentVideo = document.getElementById(id);
        currentVideo.animate([{ opacity: from }, { opacity: to }], { duration: duration });
        currentVideo.addEventListener("ended", function(e)
        {
            e.currentTarget.animate([{ opacity: to }, { opacity: from }], { duration: duration, fill: "forwards" });
        });
    };
    
    // you can call this in each frame
    stage.on("drawend", root.onDrawEnd, null, true, { id: "video0", from: 0, to: 1, duration: 1000 });


    Regards,

    JC

    35 replies

    mnarlockAuthor
    Inspiring
    Jul 2, 2024 7:48 PM UTC

    Thank you to you both! I'll give this a shot. 

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 2, 2024 7:54 PM UTC

    thumbs up 

    Translate
    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    Jul 2, 2024 12:29 PM UTC

    Hi.

     

    Video components wrap DOM elements, so you'll need CSS for it.

     

    You can add the styles in the HTML file using a publish template or use the .animate method in JavaScript, for example.

    var root = this;
    
    // the two methods below could live in the first frame
    root.onDrawEnd = function(e, data)
    {
        root.fadeVideo(data.id, data.from, data.to, data.duration);
    };
    
    root.fadeVideo = function(id, from, to, duration)
    {
        currentVideo = document.getElementById(id);
        currentVideo.animate([{ opacity: from }, { opacity: to }], { duration: duration });
        currentVideo.addEventListener("ended", function(e)
        {
            e.currentTarget.animate([{ opacity: to }, { opacity: from }], { duration: duration, fill: "forwards" });
        });
    };
    
    // you can call this in each frame
    stage.on("drawend", root.onDrawEnd, null, true, { id: "video0", from: 0, to: 1, duration: 1000 });


    Regards,

    JC

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 2, 2024 1:48 PM UTC

    if you put that code on the main timeline, prefix that code with

     

    var root = this;

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Jul 2, 2024 1:57 PM UTC

    Thanks a lot, k!

     

    Totally forgot.

     

    Updated the answer to not cause confusion.

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 1, 2024 9:38 PM UTC

    what's the video component instance name?

    Translate
    mnarlockAuthor
    Inspiring
    Jul 1, 2024 9:49 PM UTC

    For this button it's video_scarcity

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 1, 2024 11:11 PM UTC

    i didn't realize this is more trouble than it's worth. 

     

    to work around the problems, put a stage colored moveiclip over your video and fade it out and in when you want to fade your video in and out, resp.

     

    function fadeInF(mc){

    createjs.Tween.get(mc).to({alpha:1}, 1000);

    }

    function fadeOutF(mc){

    createjs.Tween.get(mc).to({alpha:0}, 1000)

    }

    Translate