How to pass PHP variable as FlashVars via SWFObject

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-24T19:43:01Z Indexed on 2010/05/24 19:51 UTC
Read the original article Hit count: 463

Filed under:
|
|
|

I am trying to take a PHP variable and pass it along to Flash via Flash vars. My end goal is to pass a string formatted as XML to Flash, but because I'm struggling I've stripped everything down to the basics. I'm just trying to pass a simple PHP string variable to Flash via FlashVars with SWFObject but something isn't right. The page won't load when I try to pass the variable inside of php tags, but it will load if I just pass a hard coded string. The basic structure of my page is that I have some PHP declared at the top like so:

PHP

<?php
     $test = "WTF";
?>

Some HTML (excluded here for simplicity sake) and then the JavaScript SWFObject Embed within my HTML:

    <script type="text/javascript" src="js/swfobject2.js"></script>
    <script type="text/javascript">
        // <![CDATA[
        var swfURL = "swfs/Init-Flash-PHP.swf";

        var flashvars = {};
            flashvars.theXML = <?php print $test ?>;

        var params = {};
            //params.menu = "false";
            params.scale = "showAll";
            params.bgcolor = "#000000";
            params.salign = "TL";
            //params.wmode = "transparent";
            params.allowFullScreen = "true";
            params.allowScriptAccess = "always";

        var attributes = {};
            attributes.id = "container";
            attributes.name = "container";


        swfobject.embedSWF(swfURL, "container", '100%', '100%', "9.0.246", "elements/swfs/expressinstall.swf", flashvars, params, attributes);


        // ]]>
</script>

And the bare essentials of the ActionScript 3 Code:

_paramObj = LoaderInfo(stage.loaderInfo).parameters;
theText_txt.text = _paramObj['theXML'];

How do I pass a PHP variable using SWFObject and FlashVars?

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about flash