I've posted the CreateFromXAML and Timer sample from my Mix talk. You can run the sample here and get the source here. The sample uses the downloader component to retrieve a ZIP archive that contains a set of XAML files. To do this, in the onLoad event, I kick-off a download of the ZIP archive:
function onLoad(sender, args, root) {
// Download big file sender, "assets.zip"
download(sender, "assets.zip");
}
function download(host, file) {
var dl = host.createObject("downloader");
dl.addEventListener("completed", downloadComplete);
dl.open("get", file, true);
dl.send();
}
This download is asynchronous and calls the downloadComplete event when finished. In this event I then use CreateFromXAML to instance the XAML files and then add them to the main Canvas. I also add an animation timer but talk about that in more detail in the next paragraph:
function downloadComplete(sender, args) {
var main = sender.findName("main");
cfx(main, sender.getResponseText("Camera.xaml"));
cfx(main, sender.getResponseText("Coffee.xaml"));
cfx(main, sender.getResponseText("Glasses.xaml"));
cfx(main, sender.getResponseText("Grass3.xaml"));
cfx(main, sender.getResponseText("Landscape.xaml"));
cfx(main, sender.getResponseText("Popcan.xaml"));
// Show first
main.children.getItem($idx).visibility = "Visible";
// Start timer
var timer = sender.findName("timer");
timer.addEventListener("completed", timerCompleted);
timer.begin();
}
Finally, I setup an animation timer to cycle through the newly created instances.