In the previous Tip of the Day, we looked at the sixth parameter to createSilverlight/ createSilverlightEx which allowed you to pass in a string as the initParams parameter.
You can also pass in a seventh parameter of type object, which is known as the user context. This can be any object you like. However, rather than retrieving it as a property of the Silverlight control, you retrieve the userContext as the second argument passed to the load event handling method
handleLoad: function(plugIn, userContext, rootElement)
As a simple example, you can create an array in default.html.JS. and pass that in as your userContext object:
var authorArray = [ "Douglas Adams", "Neil Gaiman", "Neal Stephenson" ];
context: authorArray
Since this becomes available to you only in handleLoad you'll save it in a member variable so that it will be available in every member method:
handleLoad: function(plugIn, userContext, rootElement) { this.plugIn = plugIn; this.userContext = userContext;
Using the keyword this creates a member variable that is accessible from any member method. The userContext looks like a variable, but what you passed in is an array, and so you can use it as an array.
handleMouseUp: function(sender, eventArgs) { alert("this.userContext[0] = " + this.userContext[0]); alert("this.userContext[1] = " + this.userContext[1]); alert("this.userContext[2] = " + this.userContext[2]); },
I will be posting a "How Do I" video on using the sixth and seventh parameter of CreateObject, very soon.