How to pass javascript string variable as a real setting?

Go To StackoverFlow.com

1

I have a javascript question. I'm trying to dynamically build a plugins string variable (optPlugins) and insert into a setup for jwplayer but it doesn't work. For example:

This does not work:

function jsCreatePlayer(sStartVid)
{
var optPlugins = '{ "dplaylists-1": { "dxmlpaths": "/jw/playlist_latest.xml", "dposition": "top", "dskin": "/jw/DPlaylistsSample.swf", "dtarget": "_self" } }';

jwplayer('mainplayer').setup({
'flashplayer': '/jw/player.swf',
'file': sStartVid,
'plugins': optPlugins,
'autostart': 'true',
'width': '577',
'height': '324'
});
}

This does:

function jsCreatePlayer(sStartVid)
{
jwplayer('mainplayer').setup({
'flashplayer': '/jw/player.swf',
'file': sStartVid,
'plugins': { "dplaylists-1": { "dxmlpaths": "/jw/playlist_latest.xml", "dposition": "top", "dskin": "/jw/DPlaylistsSample.swf", "dtarget": "_self" } },
'autostart': 'true',
'width': '577',
'height': '324'
});
}

Note the only different between the two is I copy the optPlugins var right into the plugins:. I'm not good with this, are these JSON options or something? How would I get jwplayer's .setup to properly eval(?) optPlugins? Its not a jwplayer problem, I could just as easily have this question for jquery options too I think.

Thanks.

2012-04-04 03:16
by Ken Williams
The actual difference is that your variable optPlugins is a String, whereas in the other it's an object. If you remove the single quotes around optPlugins it should work exactly the same - gmalette 2012-04-04 03:23


2

use like following code,

var optPlugins = { "dplaylists-1": { "dxmlpaths": "/jw/playlist_latest.xml", "dposition": "top", "dskin": "/jw/DPlaylistsSample.swf", "dtarget": "_self" } };
2012-04-04 03:23
by Chamika Sandamal
Thanks, that did it. Your awesome - Ken Williams 2012-04-04 03:59
Ads