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?
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?
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.ph pVar);
} else
{
trace("loading fails...");
}
};
myLoadVars.load("http://www.mydomain.com/forFlash.php");
function afterSessionLoaded(session Name)
{
myXML.load(sessionName+".x ml");
}
myXML.onLoad = function(success)
{
if (success)
{
//do actoin on success
} else
{
trace("loading fails...");
}
};
---------------
I hope all would be clear
Rgds
Aneesh
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.ph
} else
{
trace("loading fails...");
}
};
myLoadVars.load("http://www.mydomain.com/forFlash.php");
function afterSessionLoaded(session
{
myXML.load(sessionName+".x
}
myXML.onLoad = function(success)
{
if (success)
{
//do actoin on success
} else
{
trace("loading fails...");
}
};
---------------
I hope all would be clear
Rgds
Aneesh
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].childNo des[0].chi ldNodes[0] .toString( );
trace(file.substr(file.len gth - 3, 3));
type = file.toLowerCase().substr( file.lengt h - 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!
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].childNo
trace(file.substr(file.len
type = file.toLowerCase().substr(
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?
ASKER
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?
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?
ASKER
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-AE 6D-11cf-96 B8-4445535 40000" 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-shockw ave-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?
You need to pass the session id using flashvars in the <object> and <embed> tags. For example:
<object classid="clsid:D27CDB6E-AE
<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-shockw
</object>
THEN the flash side become easier, all you need to do is call x.load(session_id + ".xml");
Make sense?
ASKER
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].childNo des[0].chi ldNodes[0] .toString( );
trace(file.substr(file.len gth - 3, 3));
type = file.toLowerCase().substr( file.lengt h - 3, 3);
trace (type);
}
};
x.load(session_id + ".xml");
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].childNo
trace(file.substr(file.len
type = file.toLowerCase().substr(
trace (type);
}
};
x.load(session_id + ".xml");
Yes, it is right and should work perfectly
Rgds
Aneesh
Rgds
Aneesh
ASKER
Hmmmm. Still not working. Does the flash embedding code look right?
<object classid="clsid:d27cdb6e-ae 6d-11cf-96 b8-4445535 40000" 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 ?flashCont entURL=vid eo.php?fil e=<?php echo "$_GET[file]"; ?>&stat=video&altContentUR L=alternat e.html&con tentVersio n=7&conten tMajorRevi sion=0&con tentMinorR evision=0& allowFlash AutoInstal l=false" />
<param name="quality" value="low" />
<param name="flashvars" value="session_id=<?php echo "$PHPSESSID"; ?>">
<embed src="flash_detection.swf?f lashConten tURL=video .php?file= <?php echo "$_GET[file]"; ?>&stat=video&altContentUR L=alternat e.html&con tentVersio n=7&conten tMajorRevi sion=0&con tentMinorR evision=0& allowFlash AutoInstal l=false" quality="low" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockw ave-flash" width="80" height="80" />
</object>
<object classid="clsid:d27cdb6e-ae
<param name="movie" value="flash_detection.swf
<param name="quality" value="low" />
<param name="flashvars" value="session_id=<?php echo "$PHPSESSID"; ?>">
<embed src="flash_detection.swf?f
</object>
What is all this?
value="flash_detection.swf ?flashCont entURL=vid eo.php?fil e=<?php echo "$_GET[file]"; ?>&stat=video&altContentUR L=alternat e.html&con tentVersio n=7&conten tMajorRevi sion=0&con tentMinorR evision=0& allowFlash AutoInstal l=false"
?
value="flash_detection.swf
?
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)
(sorry for the douple post, hit submit too soon)
ASKER
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got rid of the extra crap and it worked. Thanks for all your help!
Welcome.
Sorry for the short answer, it's late and I've put in too many hours :)