javascriptphpactionscript-3flashswfobject

How to pass variable from MySQL to SWF


I am trying to pass an ssoTicket from MySQL through a webpage and into a SWF file.

The bellow code results in null in the server log, but when I set an ssoTicket that matches, everything works fine.

There seems to be relatively little information online.

I have printed sso_ticket and it does echo the correct string.

Page

<?php
include("global.php");
if($islogged) { ?>
<?xml version=”1.0″?>
<html>
<head>
    <title><?php echo $self['sso_ticket']; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />

    <script src="js/swfobject.js" type="text/javascript"></script>
    <script type="text/javascript">
        var flashvars = {
            sso: "<?php echo $self['sso_ticket']; ?>" 
        };
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "true",
            allowScriptAccess: "always",
            bgcolor: "#FFFFFF"
        };
        var attributes = {
            id:"E4"
        };
        swfobject.embedSWF("ac.swf", "altContent", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    </script>
    <style>
        html, body { height:100%; }
        body { margin:0; }
    </style>
</head>
<body>
  <div id="altContent">
        <p><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></p>
    </div>
</body>
</html>
<?php
}
?>

SWF

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

SWF With pre-set ssoTicket

var ssoTicket:String = LoaderInfo(this.root.loaderInfo).parameters["sso"];          
if (ssoTicket == "" || ssoTicket == null) ssoTicket = "73a448e7e4a3314d2d1a3f33588df9b8";

Solution

  • Your flashvars should be a set of name=value pairs (with pairs separated by an &, not being used in your example currently but in case you add more flashvars).

    So something like this will work:

    <script type="text/javascript">
        var flashvars = {};
        flashvars.sso = "<?php echo $self['sso_ticket']; ?>";
        var params = {};
        var attributes = {};
        swfobject.embedSWF("ac.swf", "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);
    </script>
    

    There is a html generator within the swfobject project that you can plug all your values into and it will gen your static or dynamic html code for you to cut/paste into your code (swfobjectgen.html).

    Then this should work inside your SWF to assign your ticket #:

    var ssoTicket:String = LoaderInfo(this.root.loaderInfo).parameters.sso;