CreateObject
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Creates a specified object and returns a reference to it.
retval = silverlightObject.CreateObject(objectType)
Arguments
objectType |
string The name of the type of object to create. |
Return Value
Type: object
An object reference to a new object if the object was successfully created; otherwise, null.
Managed Equivalent
None
Remarks
The Downloader object is the only object that can be specified by name as the objectType parameter value for the CreateObject method in the Silverlight JavaScript implementation. If you specify an invalid objectType parameter, the CreateObject method throws an exception.
Example
The following JavaScript example shows how to invoke the CreateObject method and create a Downloader object.
// Create the event handler for initializing and executing a download request.
function onMouseLeftButtonUp(sender, eventArgs)
{
// Retrieve a reference to the plug-in.
var slPlugin = sender.getHost();
// Create a Downloader object.
var downloader = slPlugin.createObject("downloader");
// Add DownloadProgressChanged and Completed events.
downloader.addEventListener("downloadProgressChanged", onDownloadProgressChanged);
downloader.addEventListener("completed", onCompleted);
// Initialize the Downloader request.
// NOTE: Downloader APIs disallow the file:\\ scheme.
// You must run this sample over localhost: or off a server, or the following call will fail.
downloader.open("GET", "promo.png");
// Execute the Downloader request.
downloader.send();
}