0

I am using this function for playing some embedded wav files.

function playnote(note) {
  document.embeds[note].play();
}

I am getting result of expression undefined is not a function after I click on the button that calls this function

I should be using "Play" and it would work!! :)

2 Answers2

2

Paste this at the beginning of playnote(). If you use Firebug, console.debug is a better replacement of alert.

alert(document.embeds);
alert(document.embeds[note]);

I bet the second alert will yield undefined. And JavaScript can't invoke methods on undefined. Apparently embeds array/object does not contain index/field for note.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • can you explan why its happening and how these two statements will solve it ? – Abhishek Kumar Jun 20 '11 at 06:48
  • These statements are suppose to help you diagnose the problem. Based on the code snippets you've added (please edit your original question and put them there), looks like you either don't have `embeds` variables defined anywhere, it doesn't have an element at index `0` or - the element at index `0` does not have `play()` method. – Tomasz Nurkiewicz Jun 20 '11 at 06:54
  • yes. you are correct. second alert yield undefinied. how can I defined a set of music files in an array, if embed doesn't contain a field ? – Abhishek Kumar Jun 20 '11 at 07:09
  • actually, it worked. I was just using "play" when I should be using "Play"....I am such a novice – Abhishek Kumar Jun 20 '11 at 07:26
0

The fragment of code: document.embeds[note] probably resolves to nothing. It may be that this portion of the page has not loaded or the html is incorrectly formed.

It would help to post the html for this page.

IanNorton
  • 7,145
  • 2
  • 25
  • 28