Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-19-2008, 11:41 PM   #1
Registered User
Join Date: Jan 2008
Posts: 5
Default fading alpha on a video object question

Hello all,

I am attempting to use a timer in conjunction with a sprite's alpha levels to create a programmatic fade in/out for a video object. I have the fade out working wonderfully. For some reason I cannot seem to get the fade in to work properly. I am calling to a timer function that runs after the video is loaded. Once the timer finishes, I play the video. The video loads fine, but doesn't fade in, only pops to opaque when it starts to play (the holding clip, the video's parent, takes the transition fine, showing a nice fade in).

Can the video object not accept alpha values until after it is fully loaded, or does this sound like something else. I created a shape behind the video to test, and the transition is working properly, just the video alpha wont take.

Here is the class code. It is still working code, so please dont yell at me about improper coding form :P

package {
	import flash.display.*;
	import flash.events.*;
	import flash.media.*;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
	public class MainVideo extends Sprite {
		private var client:Object;
		private var nc:NetConnection;
		private var ns:NetStream;
		private var currentFile:String;
		private var uldr:URLLoader;
		private var vid:Video;
		private var volumeTransform:SoundTransform;
		private var currentTime:Number;
		private var vidAlpha:Number;
		private var holderVideoClip:Sprite = new Sprite();

		public function MainVideo(file:String) {
			currentFile = file;
			volumeTransform = new SoundTransform();
			client = new Object();
			client.onMetaData = metadataHandler;

			nc = new NetConnection();
			// Initialize the NetSteam object, add a listener for the netStatus 
			// event, and set the client for the NetStream.
			ns = new NetStream(nc);
			ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			ns.client = client;

			volumeTransform.volume = 0;
			ns.soundTransform = volumeTransform;
                                // draw test shape to see if fade is working
				var testShape:Shape = new Shape();
				testShape.graphics.drawRect(-5, -5,231,411);

			// Initialize the Video object, attach the NetStram, and add the Video
			// object to the display list.
			vid = new Video();
			vid.width = 385;
			vid.height = 183;
			vid.alpha = 1;
			holderVideoClip.alpha = 0;

			// Fade in the video.
		private function netStatusHandler(event:NetStatusEvent) {
			try {
				switch (event.info.code) {
					case "NetStream.Play.Start" :
						trace("we have lift off");
					case "NetStream.Play.StreamNotFound" :
						trace("oops not found");
					case "NetStream.Play.Stop" :
						trace("stream stopped");
			} catch (error:TypeError) {
				//error catching routines go here

		private function fadeVideoIn(){
			vid.alpha = 1;
			var fadeInTimer:Timer = new Timer(50, 20);			
			fadeInTimer.addEventListener(TimerEvent.TIMER, onInTick);
			fadeInTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerInComplete);			
			function onInTick(event:TimerEvent):void {
				// displays the tick count so far
				// The target of this event is the Timer instance itself.
				currentTime =  event.target.currentCount*.10
				currentTime = currentTime/2;
				vidAlpha = currentTime;				
				holderVideoClip.alpha = vidAlpha;
			function onTimerInComplete(event:TimerEvent):void {
				trace("Time's Up!");
				fadeInTimer.removeEventListener(TimerEvent.TIMER, onInTick);
				fadeInTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerInComplete);
				fadeInTimer = null;
		private function fadeVideoOut(){
			var fadeOutTimer:Timer = new Timer(50, 20);			
			fadeOutTimer.addEventListener(TimerEvent.TIMER, onOutTick);
			fadeOutTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerOutComplete);			
			function onOutTick(event:TimerEvent):void {
				currentTime =  event.target.currentCount*.10
				currentTime = currentTime/2;
				vidAlpha = 1-currentTime;				
				holderVideoClip.alpha = vidAlpha;
			function onTimerOutComplete(event:TimerEvent):void {
				fadeOutTimer.removeEventListener(TimerEvent.TIMER, onOutTick);
				fadeOutTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerOutComplete);
				fadeOutTimer = null;
		public function closeVideo(){
		private function removeVideo(){
				trace("video closed");
				if(this.numChildren >= 1){
				vid = null;
Thanks ahead of time for all your help,
Jason @ MontyDigital.com
Jason@montydigital.com is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What happened to duplicateMovieClip() ? matbury ActionScript 3.0 5 12-01-2007 10:05 PM
Quick FLV question esper Components 11 03-29-2007 11:56 PM
Video Project Question TheSheriff Components 4 01-23-2007 06:21 PM
Accessing Embedded Video object in custom component cbriarnold Components 0 01-11-2005 08:30 PM
Enhancing universal object methods (quick question) Mortimer Jazz ActionScript 1.0 (and below) 22 05-06-2003 11:50 AM

All times are GMT. The time now is 10:23 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.