|
-
Oct 8th, 2006, 05:29 PM
#1
Parse file name
i'm embedding some flash in a webpage - but it's a template based system and the different swf files will need to be shown at different sizes on different pages.
The file names will be like: monkey_dance_150_100.swf
so I wrote the following javascript as a test:
HTML Code:
function getDimension(filename, dimension) {
var file_array = filename.split("_");
if (dimension = 'W') {
alert(file_array[file_array.length - 2]);
} else if (dimension = 'H') {
alert(file_array[file_array.length - 1]);
}
}
and attempted to use it such ({section.image} is just the file name - it gets parsed by the template language first):
HTML Code:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="javascript:getDimension('{section.image}', 'W')" height="javascript:getDimension('{section.image}', 'H')">
<param name=movie value="{section.image}">
<param name=quality value=high>
<param name=wmode value=transparent>
<embed src="{section.image}" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="javascript:getDimension('{section.image}', 'W')" height="javascript:getDimension('{section.image}', 'H')">
</embed>
</object>
that didn't do anything. i just want it to show the parsed values at the moment (i know it wasn't returning anything)
presumably that didn't work because there isn't an event triggering the code to run - so how should i go about this?
-
Oct 8th, 2006, 08:25 PM
#2
Re: Parse file name
Generate the whole element via JavaScript. You can do this in onload event or with inline script.
-
Oct 9th, 2006, 06:55 PM
#3
Re: Parse file name
i ended up doing it inline like so:
HTML Code:
<script type="text/javascript">
//{section.image} is equivalent to monkey_dance_100_100_.swf
var filename = '{section.image}';
var file_array = filename.split('_');
document.write('<td width="' + file_array[file_array.length - 3] + '" valign="top"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' + file_array[file_array.length - 3] + '" height="' + file_array[file_array.length - 2] + '"><param name=movie value="{section.image}"><param name=quality value=high><param name=wmode value=transparent><embed src="{section.image}" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + file_array[file_array.length - 3] + '" height="' + file_array[file_array.length - 2] + '" wmode="transparent"></embed></object></td>');
</script>
is that what you had in mind?
-
Oct 9th, 2006, 09:47 PM
#4
Re: Parse file name
Well, I thought you could've added it using DOM methods. Atleast you shouldn't use document.write - it isn't very elegant way of adding data into the page. innerHTML isn't much better, it doesn't even work in Firefox 1.0 in standards compliant mode (but does work in 1.5).
Here is a guide on how to use DOM instead of innerHTML
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|