For those still having issues with this (in older versions of the platform), I've setup an example online so you can test and inspect the code - please download it from the demo, as well.
...I'm getting a weird error in the download. Please get it from the attach in this post.