开发者

Send php variables to flash using flashvars

I have a flash player embedded on page page.php?user=john using swfobject. The player calls the xml file content.php to get the results. I'm trying to get the user name from the url id. and fetch results based on that. I can get the username on page.php by doing $_GET['user'], but how can i pass that to content.php. Having read allot of articles online, i did the following,

I'm embedding the flash on page.php using swfobject like this

<script type="text/javascript">
    var flashvars = {user:"<?php $_GET[user] ?>"};
    var开发者_JAVA百科 so = new SWFObject("<?php echo $index->CFG['site']['url'];?>preview2.swf", "sotester", "1000", "400", "8", "#000000", flashvars);
    so.addParam("allowFullScreen", "true");
    so.addParam("scale", "noscale");
    so.addParam("menu", "false");
    so.write("flashcontent");
</script> 

In my AS2 file end of the file looks like

var paramList:Object = this.root.loaderInfo.parameters;
trace(paramList["user"])
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("contentp.php?user=" + user);

So basically, i'm trying to pass $_GET['user'] from page.php to my swf file which calls content.php. Then swf would pass that value to content.php. I believe i provided you with all the information needed. Any help would be appreciated.

PS: right now as i have it, looking at console, i see Request URL:http://www.domain.com/content.php?user=undefined. So it's coming as undefined.


Embed like so with SWFObject v2.2

<html>
  <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <script type="text/javascript" src="swfobject.js"></script>
  <script type="text/javascript">
    function loaded( ){
      var flashvars = { };
          flashvars.user = "<?php $_GET[user] ?>";

      var params = {};
          params.menu = "false";
          params.quality = "high";
          params.bgcolor = "#869ca7";
          params.allowFullScreen = "true";
          params.scale = "noscale";

      var attributes = {};
          attributes.id = "myFlashObject";
          attributes.name = "myFlashObject";
          attributes.align = "middle";
          attributes.allowFullScreen = "true";
          attributes.scale = "noscale";

      var tmp = "expressInstall.swf";
      var version = "8.0.0";
      var width = "1000";
      var height = "400";
      var container = "sotester"

      // verify the URL is correct
      var flashObj = "<?php echo $index->CFG['site']['url'];?>preview2.swf";

      swfobject.embedSWF(flashObj, container, width, height, version, tmp, flashvars, params, attributes);

    }
  </script>
  </head>
<body onLoad="loaded()">
  <div id="sotester">Loading Content... put alt. content here</div>
</body>
</html>



// in actionscript 3
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
var user: String = String( paramObj[user] );
trace( user );

[EDIT]

// in actionscript 2
// _level0 will have the global flashvar on it
// trace(user);

REFERENCE


There are a few ways to go about this. If you want to insert flashvars into an embedded swf, you can simply use the flashvar property on the object or embed tags:

<param name="flashvars" value="uId=<?= $_GET['user'] ?>" />

Another way to do this is to have Flash retrieve the userId itself. Because flash can call javascript, you can actually do the same thing like this:

if( ExternalInterface.available ) {
    ExternalInterface.call( "function() { return window.location.href; }" );
}

This will actually return the full URL string to flash itself, wherein you can do all the substring operations you desire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜