XML/SWF Slideshow  2.7 | XML/SWF Charts | SlickBoard(New)

 < previous 

 

Slideshow Source

 

PHP, ASP, CFML, Perl, etc.

The previous tutorial example uses the document sample.xml as a slideshow source. This is a static XML document prepared manually. However, the slideshow source can be either a static XML document, or any script generating the XML code dynamically.

For example, the source file can be sample.php, containing PHP code that generates all the XML code like this:


<?php

echo "<slideshow>";

for ( $i=0; $i<100; $i++ ){
   echo "<slide>";
   echo "   <image url='images/sample".$i.".jpg' />";
   echo "   <transition type='drop' duration='1' />";
   echo "</slide>";
}

echo "   <control bar_visible='on' />";	
echo "</slideshow>";

?>

Or, generating some XML code like this:


<slideshow>

<?php
for ( $i=0; $i<100; $i++ ){
   echo "<slide>";
   echo "   <image url='images/sample".$i.".jpg' />";
   echo "   <transition type='drop' duration='1' />";
   echo "</slide>";
}
?>

   <control bar_visible='on' />
</slideshow>

Or, generating one or more variables like this:


<slideshow>

   <slide>
      <image url='images/sample.jpg' />
      <transition type='<?php echo "drop"; ?>' duration='1' />
   </slide>
   
   <control bar_visible='<?php echo "on"; ?>' />	
</slideshow>

 


Passing variables to Slideshow Source

Pass variables to the slideshow's source in the query part of the source's URL like this:

xml_source=sample.php?control=on&user_id=658 

 

To avoid conflicts with other flash variables, convert the special characters to their hex values like this:

xml_source=sample.php%3Fcontrol%3Don%26user_id%3D658

 

The result is:

<HTML>
<BODY bgcolor="#FFFFFF">

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" 
        WIDTH="320" 
        HEIGHT="240" 
        id="slideshow" 
        ALIGN="">
<PARAM NAME=movie VALUE="slideshow.swf?xml_source=sample.php%3Fcontrol%3Don%26user_id%3D658">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#000000>

<EMBED src="slideshow.swf?xml_source=sample.php%3Fcontrol%3Don%26user_id%3D658" 
       quality=high 
       bgcolor=#000000  
       WIDTH="320" 
       HEIGHT="240" 
       NAME="slideshow" 
       ALIGN="" 
       TYPE="application/x-shockwave-flash" 
       PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>

</BODY>
</HTML>

 

The sample.php source might read the variables and generate the XML code like this:


<?php

//read the query variables
$control =  $_REQUEST['control'];
$id = $_REQUEST['user_id'];

//turn control off for all users other than user id 658	
if ( $id != 658 ){
   $control = "off";
}

?>
							
<slideshow>
   <control bar_visible='<?php echo $control ?>' />	
</slideshow>

 


Debugging

To view and debug the XML source code that the tool is receiving, type the URL of the source file directly in a browser, then use the browser's View Source command to view the XML code.

If the XML code is generated by a script as in the examples above, and the script contains errors, then the browser should display the errors.

 


Caching

If a slideshow's source is dynamic (changes over time), some browsers might download only one instance of the source file, cache it, then display the same slideshow repeatedly. To prevent browsers from caching a dynamic source file, append any unique value to its URL to keep it new. This value must be added programmatically to change with every page reload. This could be the time in microseconds, or any random number (see Passing variables to Slideshow Source above):

<HTML>
<BODY bgcolor="#FFFFFF">

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" 
	WIDTH="400" 
	HEIGHT="250" 
	id="slideshow" 
	ALIGN="">
<PARAM NAME=movie VALUE="slideshow.swf?xml_source=sample.php%3Funique_id%3D0.26440600+1128349620"> 
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#666666>

<EMBED src="slideshow.swf?xml_source=sample.php%3Funique_id%3D0.26440600+1128349620" 
       quality=high 
       bgcolor=#666666  
       WIDTH="400" 
       HEIGHT="250" 
       NAME="slideshow" 
       ALIGN="" 
       TYPE="application/x-shockwave-flash" 
       PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>


</BODY>
</HTML>

 


Central Slideshow Source

You may create a different slideshow source for each slideshow on your web site, or create one central script to generate the data for multiple or all slideshows.

Pass the slideshow's id to the source to process the related slideshow:


<?php

//which slideshow to process
$id =  $_REQUEST['slideshow_id'];

switch ( $id ){
   case 1:
   $control = "on";
   break;
   
   case 2:
   $control = "off";
   break;
   
   case 3:
   $control = "auto";
   break;
}

?>
							
<slideshow>
   <control bar_visible='<?php echo $control ?>' />	
</slideshow>

 


What Next?

Next, explore the reference section. The reference section lists and describes all the variables used to modify all the slideshow attributes.

For slideshow examples, see the gallery section and click the link below each slideshow to see its code.

 

 < previous 


Copyright © 2004-2010, maani.us