Params causes swfobject.embedSWF() not to work in IE
| Project: | SWFObject API |
| Version: | 5.x-2.0-alpha1 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Greetings,
First off: thanks for this nice, but handy module!
I am using SWFObject API in a site where I want to replace the entire content section of the site by a Flash-object. Everything worked fine in FireFox, but I found that IE wasn't playing along... After some testing it seemed like the array build-up of $params was causing the problems in IE: this routine adds all parameters to the $params array seperating every item by a comma:
var params = {
width: '800',
height: '600',
no_flash: 'Sorry, you need to install flash to see this content.',
version: '5',
type: 'movie',
bg_color: '#FFFFFF',
};
var flashvars = false;
var attributes = {};
swfobject.embedSWF('/files/ctav.swf', 'wrapper-body', '800', '600', '5', 'false', flashvars, params, attributes );
});However, also the last item is ended by a comma. When I manually added an extra item at the end of the arry (but without a comma) the site also worked in IE:
var params = {
width: '800',
height: '600',
no_flash: 'Sorry, you need to install flash to see this content.',
version: '5',
type: 'movie',
bg_color: '#FFFFFF',
foo: 'bar'
};
var flashvars = false;
var attributes = {};
swfobject.embedSWF('/files/ctav.swf', 'wrapper-body', '800', '600', '5', 'false', flashvars, params, attributes );
});If others experience the same problems, it seems like the code needs to be adjusted so it doesn't end the last parameter with a comma.
The site still doesn't work in IE under Windows 98, but I think that's more of a SWFOject issue. See also http://code.google.com/p/swfobject/issues/detail?id=1
HTH,
Marcel

#1
yes, this is completely true. you can fix this behaviour by going into theme_swfobject_api and change
// add the parametersif ($params) {
$script[] = 'var params = {';
foreach ($params as $key => $value) {
$script [] = " $key: '$value',";
}
$script[] ='};';
}
to
// add the parametersif ($params) {
$script[] = 'var params = {';
$temp = array();
foreach ($params as $key => $value) {
$temp[] = " $key: '$value'";
}
$script[] = implode(',', $temp);
$script[] ='};';
}
isnt that nice, but works. I prefer creating a new function for that, since the same procedure is done for flashvars and attributes.
/*** helper function, converts a PHP array to a JS object
*/
function jsObject($arr){
$return = '{';
if(isset($arr) && is_array($arr) && !empty($arr) ){
$tmp = array();
foreach ($arr as $key => $value) $tmp[] = "$key:'$value'";
$return .= implode(',',$tmp);
}
return $return . '}';
}
then you may alter the stuff in theme_swfobject_api more easily:
// add the parametersif ($params)
$script[] = 'var params = '. jsObject($params);
I think, this should do the job ...
#2
or you just use drupal_to_js-function ;)
#3
@japanitrat can you provide that as a patch file so we can get testing on this? Thanks!
#4
uhm, seriously I have no idea how to do that. Additionally, my swfobject_api module looks completely different now, I mean, usage and parameterlists changed, so a possible patch may crush everything.
#5
Patching is the accepted way that the drupal community contributes code- It's super helpful for understanding where the code in question goes, and making sure that it's being done against the right version. There's a great tutorial here: http://drupal.org/patch/create
I'd be glad to help walk you through it, or at the least, can you get the latest code from cvs DRUPAL-5, and apply your changes and paste the file so I can take a look at the changes in context? That would be super helpful!
#6
drupal_to_js() method has been implemented. Closing issue.