如何通过PHP变量通过SWFObject的Flash变量变量、PHP、Flash、SWFObject

2023-09-08 13:37:31 作者:不吃软饭吃软糖

我想取一个PHP变量,并沿着它传递到Flash通过Flash变量。我的最终目标是通过XML格式到Flash的字符串,而是因为我挣扎,我剥夺一切下来的基本知识。我只是想通过一个简单的PHP字符串变量通过与SWFObject的Flash变量,以闪光灯,但东西是不正确的。当我试图传递变量PHP标签内的页面将不会加载,但它会加载,如果我只是传递一个硬codeD字符串。我的网页的基本结构是,我有一些PHP宣布在像这样的顶部:

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";
?>

有的HTML(不包括在此为了简单起见),然后JavaScript的SWF对象内嵌入我的HTML:

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>

和的ActionScript 3的code中的最基本的要素:

And the bare essentials of the ActionScript 3 Code:

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

我如何通过使用SWFObject和Flash变量PHP变量?

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

感谢。

推荐答案

唉,我需要逃避Flash变量和它的工作。

Ugh, I needed to escape the Flash vars and it worked.

对于任何人的兴趣,这正是我需要改变

For anyone that's interested, this is what I needed to change

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

要这样:

flashvars.theXML = escape('<?php print $test ?>');