Skip to main content
Inspiring
July 1, 2024
Answered

Fade up/out MovieClip

  • July 1, 2024
  • 3 replies
  • 2234 views

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 has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    3 replies

    mnarlockAuthor
    Inspiring
    July 2, 2024

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

    kglad
    Community Expert
    Community Expert
    July 2, 2024

    thumbs up 

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    July 2, 2024

    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

    kglad
    Community Expert
    Community Expert
    July 2, 2024

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

     

    var root = this;

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 2, 2024

    Thanks a lot, k!

     

    Totally forgot.

     

    Updated the answer to not cause confusion.

    kglad
    Community Expert
    Community Expert
    July 1, 2024

    what's the video component instance name?

    mnarlockAuthor
    Inspiring
    July 1, 2024

    For this button it's video_scarcity

    kglad
    Community Expert
    Community Expert
    July 1, 2024

    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)

    }