Link to home
Start Free TrialLog in
Avatar of dwimberley76
dwimberley76

asked on

Flash movie with XML playlist

I'm passing a session id to a flash movie via php to use as the name of a xml playlist file. I'm using a php script to rewrite the xml playlist based on what link a user clicks on. In other words, each user generates a new xml file based on their session id and link selection. I'm naming the xml file the user's session id to prevent users from sharing a playlist file. My question is:  How can I load the session id and append it to the .xml suffix within my flash actionscript?

I have tried:

x.load("$sess.xml");
where $sess is the session_id,

and

x.load("$sess"); where $sess is the session_id.xml

Neither seems to work in the movie. My php is generating the xml file okay...

Any suggestions?
Avatar of BishopNeo
BishopNeo

try x.load($sess + ".xml");

Sorry for the short answer, it's late and I've put in too many hours :)
Avatar of Aneesh Chopra
Hi,

here is the reply in detail:
-----------------

1.
lets assume php that return the session ID to flash, has the name "forFlash.php"

2.
first of all, you should test the output of this php on browser, if it gets called directly on browser output should be in simple text format as similar to the querystring.. means, a variable name with its value.

for example: if it I typed in browser address bar " http://www.mydomain.com/forFlash.php"
output should be like this:
-----------
&phpVar=sessonValue&
-----------
Note: "&" has been used to avoid the any extra space or line break in the end. so that flash can easily read it properly.

now theflash part:

3.
Put this code on a frame of your FLA where you want to load the above php variable..
---------
var myXML = new XML();
myXML.ignoreWhite = true;
var myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success)
{
      if (success)
      {
            afterSessionLoaded(this.phpVar);
      } else
      {
            trace("loading fails...");
      }
};
myLoadVars.load("http://www.mydomain.com/forFlash.php");
function afterSessionLoaded(sessionName)
{
      myXML.load(sessionName+".xml");
}
myXML.onLoad = function(success)
{
      if (success)
      {
            //do actoin on success
      } else
      {
            trace("loading fails...");
      }
};
---------------

I hope all would be clear

Rgds
Aneesh


Avatar of dwimberley76

ASKER

I'm using the session id variable as a query string from a link (i.e., www.mydomain.com?sess=$session_id), so it prints:
www.mydomain.com?sess=(32 random digits) in the address line of the browser. Do I need to do this differently?

Here is the flash code I'm trying to altar. I tried using your code and it didn't work, but I think I may need to change part of the existing code to work with yours.

var rtmpRoot, instance, file, type;
var x:XML = new XML();
x.ignoreWhite = true;
x.onLoad = function(success) {
      if (!success) {
            trace("Cannot load XML");
      } else {
            trace("Loaded");
            //trace(this);
            
            file = this.childNodes[0].childNodes[0].childNodes[0].toString();
            trace(file.substr(file.length - 3, 3));
            type = file.toLowerCase().substr(file.length - 3, 3);
            trace (type);

      }
};

x.load($sess + ".xml");

The last line is what I've been experimenting with. Can your code work with this existing code? It's probably an easy fix, but I don't often work with actionscript, so I'm sort of learning as I go.

Thanks!
if you trace $sess what does it return?
I'm not sure how to trace... I tried the above method in the browser, but it doesn't work because the php code that passes the variable is just part of a dynamic link on the page. When I open the page in the browser, it just shows the regular page content including the links. Not sure if I'm making sense...
trace(":SESSIONID: " + $sess);

Assuming the actual variable name is $sess.  From reading your post above:
I'm using the session id variable as a query string from a link (i.e., www.mydomain.com?sess=$session_id), so it prints:
www.mydomain.com?sess=(32 random digits) in the address line of the browser. Do I need to do this differently?

I have to ask, how do you pass the session id to Flash?
That's what I'm trying to figure out! I've tried embedding the variable in the object code on the page where the flash movie is embedded, (i.e., <param name="sess" value="<?php echo "$sess"; ?>">) but not sure if it's actually passing the variable or not.
Ah ha!

You need to pass the session id using flashvars in the <object> and <embed> tags.  For example:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="577" height="197">
      <param name="movie" value="mySwf.swf">
      <param name="quality" value="high">
      <PARAM NAME="flashvars" VALUE="session_id=<?php echo "$sess"; ?>">
      <embed src="Flash/mySwf.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="577" height="197"></embed>
    </object>


THEN the flash side become easier, all you need to do is call x.load(session_id + ".xml");

Make sense?

Would the actionscript look like this, then?

var rtmpRoot, instance, file, type;
var x:XML = new XML();
x.ignoreWhite = true;
x.onLoad = function(success) {
      if (!success) {
            trace("Cannot load XML");
      } else {
            trace("Loaded");
            //trace(this);
            
            file = this.childNodes[0].childNodes[0].childNodes[0].toString();
            trace(file.substr(file.length - 3, 3));
            type = file.toLowerCase().substr(file.length - 3, 3);
            trace (type);

      }
};

x.load(session_id + ".xml");
Yes, it is right and should work perfectly


Rgds
Aneesh
Hmmmm. Still not working. Does the flash embedding code look right?

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" width="80" height="80">
<param name="movie" value="flash_detection.swf?flashContentURL=video.php?file=<?php echo "$_GET[file]"; ?>&stat=video&altContentURL=alternate.html&contentVersion=7&contentMajorRevision=0&contentMinorRevision=0&allowFlashAutoInstall=false" />
<param name="quality" value="low" />
<param name="flashvars" value="session_id=<?php echo "$PHPSESSID"; ?>">
<embed src="flash_detection.swf?flashContentURL=video.php?file=<?php echo "$_GET[file]"; ?>&stat=video&altContentURL=alternate.html&contentVersion=7&contentMajorRevision=0&contentMinorRevision=0&allowFlashAutoInstall=false" quality="low" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="80" height="80" />
</object>
What is all this?
value="flash_detection.swf?flashContentURL=video.php?file=<?php echo "$_GET[file]"; ?>&stat=video&altContentURL=alternate.html&contentVersion=7&contentMajorRevision=0&contentMinorRevision=0&allowFlashAutoInstall=false"

?
Unless you have hundreds of swfs with unique names you will never load the file.  if those are parameters that you are passing (or trying to pass) to Flash use flashvars.  
(sorry for the douple post, hit submit too soon)
The majority of those variables are used in the flash player;  it was a free download, so I'm not sure of the purpose on most of them. The file variable is something I added to call data from a database and display outside of the flash movie on the player page.
Should mention that when I look at the source code on the player page after adding the session id parameter, it doesn't show up in the code for some reason...
ASKER CERTIFIED SOLUTION
Avatar of BishopNeo
BishopNeo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Got rid of the extra crap and it worked. Thanks for all your help!
Welcome.