Novalis
Novalis

Reputation: 2325

Passing Variables from HTML to Flash ActionScript 3.0

I just want to pass some parameters to ActionScript 3.0 from HTML. When I search for it I see that I can use I CAN USE [ flashvars ]

 <param name="flashvars" value="serverUrl=rtmp://X.X.X.X/live&streamName=Camera.stream">

And can access those paramters from AS3 :

var serverUrl : String =  root.loaderInfo.parameters.serverUrl;
var serverStreamName : String = root.loaderInfo.parameters.serverStreamName;

But when I try this, I see that serverUrl and serverStreamName are null:

var txt:TextField = new TextField(); 
txt.text =" URL: " + serverUrl ;
addChild(txt)

What I am doing wrong? Any idea?

Note:

My HTML which call SWF file:

<noscript>
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="..."....>
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="false" />
    <param name="movie" value="CustomVideoPlayer.swf" />
    <param name="flashvars" value="serverUrl=rtmp://X.X.X.X/live&streamName=Camera.stream">
    <param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />   
    <embed src="CustomVideoPlayer.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="CustomVideoPlayer" ...>
    </object>
</noscript>

And try to reach those paramters from AS3 like this:

var serverUrl : String =  root.loaderInfo.parameters.serverUrl;
var serverStreamName : String = root.loaderInfo.parameters.serverStreamName;

Upvotes: 0

Views: 4872

Answers (2)

Lars Bl&#229;sj&#246;
Lars Bl&#229;sj&#246;

Reputation: 6127

One thing that could cause the parameters to be missing, being null, is if you haven't specified flashvars also in the <embed> tag.

The <param> tag is used together with the <object> tag, and is read by browsers that render/execute the <object> tag, but not by the browsers that instead use the <embed> tag. The <embed> tag in your example is shortened, as is mine here, so maybe you already have it, but you would need to include the flashvars there also, like:

<embed src="CustomVideoPlayer.swf" flashvars="serverUrl=rtmp://X.X.X.X/live&streamName=Camera.stream" ...>

In other words, you need to include the flashvars twice, once for <object> and once for <embed>, as with other things such as allowFullScreen.

Upvotes: 0

loxxy
loxxy

Reputation: 13151

I would have commented to use object tag instead of embed, EMBED vs. OBJECT

But now with all the support for embed by HTML5, I'm unsure.

Whatever be the case, I would always, prefer using using a popular library like swfobjecct, simply for the sake of convenience & being on the safe side.

With that being said, this is how you do it with swfobject & Javascript :

 var flashVars = {};
 flashVars.parameter1 = "abc";
 flashVars.parameter2 = "bbc";    

 swfobject.embedSWF("myMovie.swf", "myDIV", "720", "600", "9.0.0", "expressInstall.swf", flashVars, {}, {}, swfLoadComplete);

Upvotes: 2

Related Questions