• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Fade up/out MovieClip

Contributor ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

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.

Views

892

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 02, 2024 Jul 02, 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([{ opa
...

Votes

Translate

Translate
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

what's the video component instance name?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

For this button it's video_scarcity

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

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)

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

that can't work either.  

 

i can say it's doable, but it would take me more than 15 minutes to figure it out, and that's beyond my volunteer limit.  maybe someone else will help or hire someone.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

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

 

var root = this;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

Thanks a lot, k!

 

Totally forgot.

 

Updated the answer to not cause confusion.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

no problem, and good post!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

So the only way I could get it to work was to put your code on every frame that had video followed by:

 

stage.on("drawend", root.onDrawEnd, null, true, { id: "video0", from: 0, to: 1, duration: 1000 });

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

there are better ways to handle that, but if you have something that works, leave it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

Curious, though. How should it be done properly? I would have thought defining those functions in frame 0 would have worked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

use one video component instance.  change its src property to change mp4's displayed 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

You can also code the CSS in the HTML or in a CSS file and then only change the classes using JavaScript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

Quick question on the approach listed above. When I run a video via a button and it completes...then click another button and it completes...if I go back to the original button it fades up, but then disappears immediately. 

 

Any thoughts on why? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

you have more than one fade running. eg, you have two button listeners when the problem occurs.

 

can you see how your re-adding the listener?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

That makes sense. Is there a way to stop a listener before another starts?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

yes.

 

for anything you want to execute once, use

 

if(!this.alreadyExecuted){
// the code 

this.alreadyExecuted=true;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

That didn't work, I'm afraid. The way I used your suggestion was as follows, maybe I interpeted it wrong or applied it incorrectly:

 

/*FADE IN/OUT VIDEOS*/
var root = this;
// Set up
root.onDrawEnd = function(e, data)
{
root.fadeVideo(data.id, data.from, data.to, data.duration);
};
 
if(!this.alreadyExecuted){
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" });
    });
};
this.alreadyExecuted=true;
}
 
// Fade
stage.on("drawend", root.onDrawEnd, null, true, { id: "video_lead", from: 0, to: 1, duration: 2000 });

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

Basically, every video that has played through completely once and faded away, upon next button push will fade up, then disappear.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

what are you doing to prevent multiple button listeners?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

Well, honestly, not a darn thing. I'm not sure how to manage such a thing. Basically, all the buttons sit on the timeline. When a button is pushed, the header jumps to a specific frame and plays the video at that frame. On each of those frames I have actions that stop at the frame, then execute the functions for fade up/down as you see above.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

you have code that adds listeners to buttons, correct?

 

that code needs to execute once, only.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

Yes, each button has the below, with a different frame indicated depending on which video is to be played.

 

this.lead_btn.addEventListener("click", fl_ClickToGoToAndStopAtFrame_2.bind(this));
function fl_ClickToGoToAndStopAtFrame_2()
{
this.gotoAndStop(0);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2024 Jul 11, 2024

Copy link to clipboard

Copied

the addEvent...  needs to execute once

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines