Reputation: 7479
this must be some JavaScript concept that I am not grasping yet..
For some odd reason the id of thisSound returns undefined! why??
console.log("o: "+o.id+" - "+decodeURI(soundURL));
// create sound
thisSound = soundManager.createSound({
id:o.id,
url:decodeURI(soundURL)
});
console.log("thisSound: "+thisSound.id+" - "+thisSound.url);
the console :
o: Sound0 - http://api.soundcloud.com/tracks/76673175/stream?client_id=e992d357c0914e9b65ba17f459720fc0
thisSound: undefined - http://api.soundcloud.com/tracks/76673175/stream?client_id=e992d357c0914e9c65ba17f459720fc0
Upvotes: 0
Views: 178
Reputation: 13916
The code you provided doesn't “obviously” define the id
of the returned object.
// create sound
thisSound = soundManager.createSound({
id:o.id,
url:decodeURI(soundURL)
});
Let's say I write the function createSound
for you:
var soundManager = {
createSound: function (options) {
// do internal magic here
createSound(options);
// return public API here
return {
getId: function () {}
}
}
};
So, my point here is that if there is a third-party function, you should follow the docs of whoever created that function, and SoundManager apparently doesn't return an object with id
property defined on it. It “returns a SMSound object instance” – and what is that object, please find out in the docs.
Upvotes: 1
Reputation: 1368
I know nothing about the soundcloud library, although the function createSound
seems asyncronous... (It's like I/O Stuff, the most of the I/O operations in javascript -and the other languages- are async ).. Is it possible when you have called the console.log
thisSound hasn't been fully created yet? Maybe you could emulate a setInterval()
behaviour with a lot of time and this code works... (although I believe you should use a callback function for this).
Upvotes: 0