thesoundsmith Posted May 7, 2009 Share Posted May 7, 2009 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 More sharing options...
justsomeguy Posted May 7, 2009 Share Posted May 7, 2009 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 More sharing options...
thesoundsmith Posted May 8, 2009 Author Share Posted May 8, 2009 Exactly what I was looking for! A way to pass the variable. Perfect, justsomeguy. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.