Login / Sign Up

Your cart has 3 products totalling 214.00 USD

Add GET and POST variables to Flash files through FlashVars

 

 

Using SWFObject is the simplest and best way to embed SWF files into HTML.

Download swfobject.zip file and put the swfobject.js next to the PHP file which embeds the SWF (note that the PHP script below won’t work if the file has an .html extension, and you’ll have to test it on a webserver which has PHP installed).

<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
<?php
if(count($_GET) > 0 || count($_POST) > 0) {
 $phpFlashVars = "";
 foreach ($_GET as $var => $value) {
    $phpFlashVars .= 'flashvars.'.$var.'="'.$value.'";';
 }
 foreach ($_POST as $var => $value) {
    $phpFlashVars .= 'flashvars.'.$var.'="'.$value.'";';
 }
}
print($phpFlashVars);
?>
var params = {};
var attributes = {};
swfobject.embedSWF("main.swf", "flashDiv", "600", "750", "9.0.0", false, flashvars, params, attributes);
</script>
</head>
<body>
<div id="flashDiv"></div>
</body>
</html>

 

So let’s say you’re naming this file main.php and you’re putting it in the root folder of your webserver.
Accessing www.yourserver.com/main.php?var=value will send the var variable with the specified value to the main.swf file.
Now you can use that value in Flash!
In ActionScript 2 you can simply access _root.var
Note that _root.var has the type String and you’ll have to convert it if it’s a number for example Number(_root.var);
In ActionScript 3 it’s root.loaderInfo.parameters["var"]

 

  • COMMENTS
  • SEARCH COMMENTS
KoJoT

THANK YOU!!!!!!! You saved my life! Amazing work!

Posted 1 Month Ago
Dejan

Hi Snowcat,

after admiring your work I went and buyed your whole package. Its great. Just have one problem. My designer said, that your flv player (which supports mp4) wont play mp4 files. It just wont load it. Flv files work great, but not mp4.

Is there something he is doing wrong ?

Thank you and keep up the good work.

Regards,

Dejan

Posted 1 Year Ago
Rafael Ziah

Hi Snowcat,

Your work is fabulous. I just purchased one of your players (FLV Video Player) and I have noticed that the Full Screen button doesn't work.

Would you be so kind to reply with a quick note about this? Perhaps it is not enabled?

Thanks so much. Whenever you have a chance.

-Rafael

Posted 1 Year Ago
snowcat

Hi Dejan,

Thanks for your appreciation.

FLVs and SWFs are two completely different formats.

I'm not sure what you mean by "play SWF video files" but I believe you actually referred to FLV video files.

Google it to see the difference between the two.

Thanks,
Snowcat

Posted 1 Year Ago
Dejan

Hi Snowcat,

I have been admiring your work for two weeks now (since I found flashcomponents.net).

My post however has nothing to do with "Add GET and POST variables to Flash files through FlashVars", but I have a question regarding your FLV VIDEO PLAYER. Its maybe a stupid question, but does this player also play SWF video files?

I apologize for commenting in the wrong category, but I didnt know where to ask, you can delete my post after.

Kind regards,

Dejan

Posted 1 Year Ago

Leave a Reply

Only alphanumeric characters allowed
Please type a message!
Format your comments using Textile: *bold*, _italic_, "link text":address, @code@