Search code examples
embedyoutube-apisample

Change the playing video


I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video

It works well when runned from the playground page. But if I create a new localfile with the source code provided as sample I get the following error:

ytplayer is not defined

at line 40:

if(ytplayer) {
      ytplayer.loadVideoById(videoID);
}

It looks like for some reason I don't get access to some part of the javascript needed by the sample.

Is it just me? Or sample code don't run outside the playground page?


Solution

  • This has to do with same-domain restrictions in Flash. Local files trying to access resources on the internet counts as "cross-domain" access. To whitelist your local file, add it's location to the global security settings. Click on "Edit locations..." and then "Add location...".