Jump to content

How To Simplify The Loading Of This Script


thesoundsmith

Recommended Posts

I am recoding my video pages to use javascript instead of <embed> code. A typical new page is here:my test page with javascriptThere is a fair amount of identical script that needs to be loaded into each page. But one line needs to be unique, the line that identifies the file to load (D'oh!)Here is the script from the <head> section:

<script type="text/javascript" src="swfobject.js"></script><script type="text/javascript">  var flashvars =  {	'file':								  'playb3.xml',	'frontcolor':							'#070707',	'backcolor':							 '#E2E2E2',	'lightcolor':							'#0000FF',	'screencolor':						   '#070707',	'playlist':							  'bottom',	'playlistsize':						  '120',	'repeat':								'list',	'id':									'playerId',	'autostart':							 'false',	'image':								 'dpic3.jpg'  };  var params =  {	'allowfullscreen':					   'false',	'allowscriptaccess':					 'sameDomain',	'bgcolor':							   '#C0C0C0',	'wmode':								 'window'  };  var attributes =  {	'id':									'playerId',	'name':								  'playerId'  };  swfobject.embedSWF('player.swf', 'player', '480', '480', '9.0.124', false, flashvars, params, attributes);</script><script type="text/javascript">  var player = null;  function playerReady(obj)  {	player = gid(obj.id);  };  function loadNplay(file, image, title, description)  {	player.sendEvent('STOP');	player.sendEvent('LOAD', {file:file, image:image, title:title, description:description});	setTimeout("player.sendEvent('PLAY', 'true')", 400);  };  function gid(name)  {	return document.getElementById(name);  };

Is there an elegant way to include this in each page? I thought of a php require of the first part up to the file id line, then adding the file id line as a unique element, then another php require to load the rest. A: I tried this and it worked, but...B: is there a better way? Thanks.

Link to comment
Share on other sites

That's not a bad way to do it. You could also put the filename inside a PHP variable and include the whole thing.embedswf.js.php:

  var flashvars =  {	'file':								  '<?php echo $play_file; ?>',	'frontcolor':							'#070707',	'backcolor':							 '#E2E2E2',	'lightcolor':							'#0000FF',	'screencolor':						   '#070707',	'playlist':							  'bottom',	'playlistsize':						  '120',	'repeat':								'list',	'id':									'playerId',	'autostart':							 'false',	'image':								 'dpic3.jpg'  };  var params =  {	'allowfullscreen':					   'false',	'allowscriptaccess':					 'sameDomain',	'bgcolor':							   '#C0C0C0',	'wmode':								 'window'  };  var attributes =  {	'id':									'playerId',	'name':								  'playerId'  };  swfobject.embedSWF('player.swf', 'player', '480', '480', '9.0.124', false, flashvars, params, attributes);

Then on your other page:

<script type="text/javascript" src="swfobject.js"></script><script type="text/javascript"><?php$play_file = 'playb3.xml';include 'embedswf.js.php';?></script>...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...