1
votes

I am working on a real estate website, there will be multiple properties each with it's own home page. Each property home page will a different intro video that will play after the page loads.

I am using Flash to play the video, getting the video file name from a flashvar.

I am using Flash Pro CS4 and ActionScript 3.0, this is the code I have so far (pretty rudimentary) which is working fine as far as it goes:

//VARIABLLE DECLARATIONS
var video;
var nc;
var ns;
var video_file;

//Get Flashvar intro_video_file
video_file = root.loaderInfo.parameters.intro_video_file;

//RUN ON STARTTUP
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = this;
video = new Video(560, 315);
addChild(video);
video.attachNetStream(ns);

ns.play(video_file);

but I would like to have the video load and fade in before playing and then fade out after it finishes instead of just hanging there

The fade in is less important.

I am somewhat of a beginner with Flash and ActionScript, can someone please give me some pointers on how to accomplice this?

2

2 Answers

0
votes

One possibility is to adjust the alpha property of the Video:

video.alpha = .5;

This would have to be handled through timed events though:

tmr = new Timer(500, 0);
tmr.addEventListener(TimerEvent.Timer, onTimer);
tmr.start();
.
.
.
private function onTimer(pEvent:TimerEvent):void
{
    video.alpha += .125; // or -=, case depending
    if (video.alpha == 1.0)
    {
        tmr.stop();
        tmr.removeEventListener(TimerEvent.Timer, onTimer);
    }
}

These are just sample int and Number values that have been provided; you'll have to adjust them as necessary. But just realize that Timer objects in ActionScript 3 tend to be pretty bad about not ticking more than a couple of times a second, at least if you don't set things up in potentially awkward ways. So this should work in many cases, but if you want to, let's say, decrement the alpha value by .01 20 times a second, this may or may not be the best option for you.

0
votes

I posted the above question as a different user by mistake, but wanted to share what I so far ended up with.

import flash.utils.Timer;
import flash.events.TimerEvent;

function fadeOut() {
    function onTimer(pEvent:TimerEvent):void
    {
        video.alpha -= .125; // or -=, case depending
        if (video.alpha == 0)
        {
            myTimer.stop();
            myTimer.removeEventListener(TimerEvent.TIMER, onTimer);
        }
    }
    var myTimer:Timer = new Timer(40, 0);
    myTimer.addEventListener(TimerEvent.TIMER, onTimer);
    myTimer.start();
}

function fadeIn() {

    function onTimer(pEvent:TimerEvent):void

        ns.pause();
        video.alpha += .125; // or -=, case depending
        if (video.alpha == 1.0)
        {
            myTimer.stop();
            myTimer.removeEventListener(TimerEvent.TIMER, onTimer);
            ns.resume();
        }
     }
     var myTimer:Timer = new Timer(40, 0);
     myTimer.addEventListener(TimerEvent.TIMER, onTimer);
    myTimer.start();
}



//VARIABLLE DECLARATIONS
var video;
var nc;
var ns;
var video_file;


function statusHandler(event:NetStatusEvent):void 
{ 
    switch (event.info.code) 
    { 
        case "NetStream.Play.Start": 
            fadeIn();
            break; 
        case "NetStream.Play.Stop": 
        fadeOut();
            break; 
    } 
}



//Get Flashvar video_file
video_file = root.loaderInfo.parameters.intro_video_file;

//RUN ON STARTTUP
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = this;
video = new Video(560, 315);
addChild(video);
video.attachNetStream(ns);
ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler); 
ns.play(video_file);
video.alpha = 0;

working example