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

Code:
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();
			nc.connect(null);
			// 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.beginFill(0xff0000);
				testShape.graphics.drawRect(-5, -5,231,411);
				testShape.graphics.endFill();
				holderVideoClip.addChild(testShape);


			// 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.attachNetStream(ns);
			vid.alpha = 1;
			holderVideoClip.alpha = 0;
			holderVideoClip.addChild(vid);
			addChild(holderVideoClip);


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

		private function fadeVideoIn(){
			trace("startFade");
			vid.alpha = 1;
			var fadeInTimer:Timer = new Timer(50, 20);			
			fadeInTimer.addEventListener(TimerEvent.TIMER, onInTick);
			fadeInTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerInComplete);			
			fadeInTimer.start();
	
			function onInTick(event:TimerEvent):void {
				trace((event.target.currentCount/2)*.10)
				// 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;
				ns.play(currentFile);
			}
		}
		private function fadeVideoOut(){
			var fadeOutTimer:Timer = new Timer(50, 20);			
			fadeOutTimer.addEventListener(TimerEvent.TIMER, onOutTick);
			fadeOutTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerOutComplete);			
			fadeOutTimer.start();
	
			function onOutTick(event:TimerEvent):void {
				trace((event.target.currentCount/2)*.10)
				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;
				removeVideo();
			}
		}
		public function closeVideo(){
			fadeVideoOut();		
		}
		private function removeVideo(){
				trace("video closed");
				ns.close();
				if(this.numChildren >= 1){
					removeChild(holderVideoClip);
					holderVideoClip.removeChild(vid);
				}
				vid = null;
		}
	
	}
}
Thanks ahead of time for all your help,
Jason @ MontyDigital.com
Jason@montydigital.com is offline   Reply With Quote
Reply


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 05:01 AM.

///
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.