« [Flash] Erroneous Flash 8 AS Error when Accessing Static Members | Main | [Flash] Flash IDE Crashes During Font Initialization Fix! »
January 10, 2006
[Forehead Slapping Moment] Flvs not Playing
Today I had one of the forehead slapping moments when I couldn’t figure out why dynamically loading flvs weren’t playing in a custom Flash 7 Video Player component that I built.
I spent a good 30 minutes trying to figure out why my video wasn’t loading. At first I thought I had a naming conflict (nope), or that a class was silently not loading (negative) and then I quadrupled checked all my syntax and even went as far as copying and pasting the sample code (still didn’t work).
15 minutes later and I was still scratching my head so I start thinking that maybe the flv was corrupted. After trying 3 different "corrupted" flvs (I was in denial) I gave up and decided to take a break and get something to eat.
I was outside half way through with my Starkist Lunch To Go (http://www.starkist.com/products/lunchtogo.html) when it came to me; out of the blue, as clear as day, like a light from Heaven had shun down upon my very being:
I was declaring my NetConnection and NetStream Objects inside of a function:
// bad mojo
function loadFLV(source:String):Void
{
var connection = new NetConnection();
var connection.connect(null);
var stream = new NetStream(connection);
this.video_mc.attachVideo(stream);
stream.play(source);
}
// good times
function loadFLV(source:String):Void
{
this.connection = new NetConnection();
this.connection.connect(null);
this.stream = new NetStream(this.connection);
this.videoContainer.attachVideo(this.stream);
this.stream.play(source);
}
This is a simplified example, but illustrates my problem.
What through me off was that the code samples showed timeline code and declared both the NetConnection and NetStream objects in local variables so when I double checked my ActionScript that was in a method of a class everything seemed to match up.
To be honest this isn’t the first time I’ve done this so for future reference and to possibly help anyone else with a minor oversight I’m blogging it!
-erik
Posted by erikbianchi at January 10, 2006 01:10 AM