Passing FlashVars using SwfObject

Overview
I’m working with FMS 3, and extending the vod player. the end result is to be able to load a movie through the use of a flashvar, so i can use one copy of the swf file and simply send which movies i want to be played through to the player.

The AS where i’m attempting to feed in the information is as follows:


var movieUrl:String = root.loaderInfo.parameters["filename"];

And i’m passing the flashvars using swfobject.


<script type="text/javascript">
var flashvars = {};
flashvars.filename = "rtmp://172.16.10.213/vod/Statlock.flv";
var params = {};
var attributes = {};
swfobject.embedSWF("vodtest.swf", "flashDiv", "660", "700", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>

Well, the video never seems to load. my AS file works properly if i assign the value of the movie to the movie variable.

var movieUrl:String = "rtmp://172.16.10.213/vod/Statlock.flv";

Any idea’s what may be going wrong here?

will it work if you try this?

LoaderInfo(this.root.loaderInfo).parameters["filename"];

Didn’t work.

is there a certain way i should be exporting the movie?

I have 2 files, vodtest.fla & vodtest.as.

When i test the movie from flash, it doesn’t load where it’s not accepting a parameter.

I open the same movie in a web browser and it still does not load, whereas it should be accepting the runtime parameter. Should i be doing something different?

this is working for me in ff3/ie7

flash document class

package {
	import flash.display.Sprite;
	import flash.display.LoaderInfo;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class Test extends Sprite
	{
		public function Test()
		{
			var tf:TextField = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.appendText( "filename: " + LoaderInfo(this.root.loaderInfo).parameters["filename"] );
			addChild(tf);
		}
	}
}

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<script type="text/javascript" src="swfobject.js"></script>
		<script type="text/javascript">
			var flashvars = {};
			flashvars.filename = "rtmp://172.16.10.213/vod/Statlock.flv";
			var params = {};
			var attributes = {};
			swfobject.embedSWF("Test.swf", "flashDiv", "550", "400", "9.0.0", false, flashvars, params, attributes);
		</script>
	</head>
	<body>
		<div id="flashDiv">
			<a href="http://www.adobe.com/go/getflashplayer">
				<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
			</a>
		</div>
	</body>
</html>

i can get that to work either so apparently i’m doing something wrong. my AS3 skills are quite rusty.

I inserted your sample AS into a new flash document and copied and pasted the snippet in layer 1, and exported. is there anything i’m missing here?

I’ve attached a screenshot of my flash cs3 interface.

in as3 you can have a document class which goes in an external file instead of the timeline. remove any code from the timeline and put it in a file called “Test.as”. if you open publish settings and click the actionscript button you should see the option to set a document class for the file; enter “Test” and make sure that the .as file you saved before is in the same directory as your .fla

Wow, no idea what is going on here.

Here’s what i got.
Complier Errors - 1 reported
Location test.as, Line 1: 5008: The name of definition ‘Test’ does not reflect the location of this file. Please change the definition’s name inside this file, or rename the file. C:\Documents and Settings\moorert\My Documents\Flash\LMS Video Player\swfobject\ est\ est.as

I have test.fla & test.as in the same folder, C:\Documents and Settings\moorert\My Documents\Flash\LMS Video Player\swfobject\ est\ est.as.

The Document class in test.fla points to test.as in the document class in the properties window.

When i published the movie, and opened my webpage the swf file still didn’t accept my flashvars.

Here is the copy of my simple html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title>Test Flash Vars</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<script type="text/javascript" src="swfobject.js"></script>
		<script type="text/javascript">
			var flashvars = {};
			flashvars.filename = "rtmp://172.16.10.213/vod/Statlock.flv";
			var params = {};
			var attributes = {};
			swfobject.embedSWF("Test.swf", "flashDiv", "550", "400", "9.0.0", false, flashvars, params, attributes);
		</script>
	</head>
	<body>
		<div id="flashDiv">
			<a href="http://www.adobe.com/go/getflashplayer">
				<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
			</a>
		</div>
	</body>
</html>

And here is the contents of test.as

package {
	import flash.display.Sprite;
	import flash.display.LoaderInfo;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class Test extends Sprite
	{
		public function Test()
		{
			var tf:TextField = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.appendText( "filename: " + LoaderInfo(this.root.loaderInfo).parameters["filename"] );
			addChild(tf);
		}
	}
}

the document class is case sensitive; should be “Test” and the class file should be “Test.as”. attached are the files i was using.

cool. so yours seems to work, but i’m still not getting any love from flash on mine. I’ve attached my files (it’s 1.3 MB in size so sp wouldn’t allow me to upload it). You can see in vodtest.as line 11 where i’m attempting to call the video from the flashvars.

var movieUrl:String = LoaderInfo(this.root.loaderInfo).parameters["filename"];

Again, if i use a direct link to a flv such as

var movieUrl:String = "rtmp://172.16.10.213/vod/Statlock.flv";

the movie will play fine. Maybe you can see something i’m missing here for the loaderinfo not to work.

the LoaderInfo class is as3. FlashVars in an as2 project are set right on the root timeline. so if you change this:

var movieUrl:String = LoaderInfo(this.root.loaderInfo).parameters["filename"];

to this:

var movieUrl:String = filename;

it should work.

sweet. got it working. thanks for all the help.