Embedding Shockwave

Auto-Creating HTML to embed Shockave

When you 'Publish' a Director movie, you can select to also create HTML files to embed the Shockwave movie. You can modify the 'Publish Templates' used by Director and create your own varations. For example, if you download this publish template and add it to the Director: Publish Templates: folder, you will be able to select "Valid XHTML" in the format popup menu in the "Publish Settings" dialog box. The very helpful Tom Higgins has also produced some publish tempates that offer better plugin detection.

Dynamically Generating the HTML

The lingoworkshop uses a content management system that stores 'content' (text, images and shockwave) in marked-up text (stored in a mySQL Database). The tag for including a shockwave movie is a like this

[DCR ]Filename.dcr|320|240|An optional caption[/DCR]

Before displaying content, the 'content text' is run through a function which extracts the filename, width, height and caption and generates from this tag and inserts the appropriate Object and Embed# tags. This function looks like this:

SCRIPT

// $text is the raw, marked up content text

$pat = "/\[DCR\](.*?)\[\/DCR\]/";

$text = preg_replace_callback($pat, "Insert_dcr_Callback", $text);

// continue converting the text in XHTML



The callback function then inserts the markup to display the specified shockwave movie.

CALLBACK FUNCTION 



function Insert_dcr_Callback($matches) {

	global $StandardsMode;

		

	$hit = $matches[1];

	list($f, $w, $h, $t) = explode("|", $hit);

	

	if ($StandardsMode) {

	

	// STANDARDS MODE

	

	$out = "

	  <object type=\"application/x-director\" data=\"/assets/dcr/".$f."\" 

	  		width=\"$w\" height=\"$h\">

		<param name=\"src\" value=\"/assets/dcr/loader.dcr\" />

		<param name=\"sw1\" value=\"$f\" />

		<param name=\"swRemote\" 

			value=\"swSaveEnabled='false' 

			swVolume='true' 

			swRestart='false' 

			swPausePlay='false' 

			swFastForward='false' 

			swContextMenu='false' \"/>

		<param name=\"swStretchStyle\" value=\"none\" />

		<img src=\"shockwaver_not.gif\" 

			width=\"$w\" height=\"$h\" alt=\"No shockwave?!\" />

	  </object>

	";

	

	} else {

	

	// COMPATIBILITY MODE	



	$out = "<object classid=\"clsid:166B1BCA-3F9C-11CF-8075-444553540000\"

 codebase=\"http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0\"

 ID=loader width=$w height=$h>

<param name=src value=\"/assets/dcr/loader.dcr\" />

<param name=\"sw1\" value=\"$f\" />

<param name=\"swRemote\" 

	value=\"swSaveEnabled='false' 

	swVolume='false' 

	swRestart='false' 

	swPausePlay='false' 

	swFastForward='false' 

	swContextMenu='false' \">

<param name=\"swStretchStyle\" value='stage' />

<param name=\"bgColor\" VALUE=\"#FFFFFF\" /> 

<param name=\"progress\" VALUE='FALSE' /> 

<param name=\"logo\" VALUE='FALSE' /> 

<param name=\"swStretchHAlign\" VALUE='Left' /> 

<param name=\"swStretchVAlign\" VALUE='Top' /> 

<embed src=\"/assets/dcr/loader.dcr\" 

	bgColor=#FFFFFF 

	progress=FALSE 

	logo=FALSE 

	swStretchHAlign=Left 

	swStretchVAlign=Top  

	width=$w 

	height=$h 

	swRemote=\"swSaveEnabled='false' 

		swVolume='false' 

		swRestart='false' 

		swPausePlay='false' 

		swFastForward='false' 

		swContextMenu='false' \" 

	swStretchStyle=stage

 	type=\"application/x-director\" 

 	pluginspage=\"http://www.macromedia.com/shockwave/download/\" 

 	sw1=\"$f\"  >

 	</embed>

</object>";



	}

	if ($t <> "")  $out = "<span class=\"figure\">\n$out\n<br />

		<span class=\"caption\">$t</span></span >";

	return $out;

}



One advantage of this approach is that that in centralises the process of writing HTML to embed the shockwave movie. This means that, for example, by modifying a single variable ($StandardsMode), it is possible to generate XHTML that validates (by default, the Lingoworkshop uses the more compatible - but non compliant- markup). Also, this callback function does a few 'extra things' - it inserts a loader movie rather than the movie to be embedded, and it adds a caption below the shockwave movie (if required).

First published 19/08/2005