0

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 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.

3
  • So what exactly does not work? Commented Jun 3, 2011 at 6:43
  • You have misspelled $GET[user]. It should be var flashvars = {user:"<?php $_GET[user] ?>"}; - missing underscore Commented Jun 3, 2011 at 7:04
  • @meouw, this is just a type. i have it correctly in my code. Commented Jun 3, 2011 at 7:13

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. But i don't think LoaderInfo(this.root.loaderInfo).parameters; works in AS2. What is the alternative was of doing this in AS2
Ahh I did not know it was AS2 you wanted.
@The_asMan So how will my actionscript look. What goes in var user:'?'
user becomes a global var on _level0 and will hold the value of the flashvar
I got it. Is _level10 the same having _root.user. Assuming flashvars have more then 1 variables. will _level10 still hold all variables as globals.
0

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.

1 Comment

I'm using swfobject. I'm already using flashvars. Not sure what i need to do in my .AS file. For your second option, where do i place the code inside my .AS file. If yes how do i pass variable user to xmlData.load("contentp.php?user=" + user);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.