Previous topic TOC

Use COM controls

Next topic

Canvas ThreeDimSim can host one or more COM controls on a Canvas window. You can use these controls to enable user input in you simulation. In order to do so first create a canvas, this is a window capable of hosting COM controls:
var c = Canvas();

Next, a  control can be created using the createObject method of the canvas, in this case a slider control is created.

var s = c.createObject("MSComctlLib.Slider");

You can position the control on the screen using the properties windowSize, windowRect and/or windowPosition:

s.windowRect = {10,10,210,50}; 	// set size and position

The control itself can be initialized by setting some properties of the control. In this example we want to set the min and max members. However, these names are also defined functions in ThreeDimSim. In order to distinguish we use the quoted member syntax.

s."min"= 0;		 
s."max" = 100;
s.TickFrequency = 10;

Furthermore the events generated by the control can be handled by defining a function, and assign this function to the event:

var b = Box(10,10,10);
function onScroll( )// define an event handler function
{
	b.position = {s.value,0,0};
};
 
s.Scroll = onScroll;//assign function onScroll as event handler

When you run this script a canvas window is displayed with a slider control. When you move the slider, the box in the scene is moved also.