In this example, a page contains two radio buttons named moveButSlow and moveButFast and one image named image1. When each radio button is down the GetState property will be set to true.
This script was written in a Script Action. Whenever, image1 is left mouse clicked, the function Move is called and depending on which radio button is currently pressed down, the image will move to its new position immediately or over a two second period
var myEvent = image1.RegisterEventHandler("lclick", this.MoveMe)
function MoveMe()
{
if(moveButSlow.GetState() == true)
{
image1.Move(180,200,2)
}
if (moveButFast.GetState() == true)
{
image1.Move(180,200)
}
}
Below is an example of the RegisterEventHandler which uses the property of the Mouse Event. The properties which are intrinsic to the mouse event are automatically passed to the function, the function has a parameter which labels the incoming property so that it can be referred to within the function. In this instance the lclick mouse event has the properties of x position and y position. The function MoveMe labels this property as eventMousePos and then assigns the x and y properties to new variables to be used by a SetPosition for a text object.
The KeyCheck function looks to see if space has been pressed and resets the position of the text object myText to 100,100.
The example uses the this keyword so the script applies to the object it is attached to.
var myEvent = this.RegisterEventHandler("lclick", this.MoveMe)
var myEvent2 = this.RegisterEventHandler("keydown", this.KeyCheck)
function MoveMe(eventMousePos)
{
var newXpos = eventMousePos.x
var newYPos = eventMousePos.y
Text.SetPosition(newXpos,newYPos,0.75)
}
function KeyCheck(eventKeypress)
{
var key = eventKeypress.key
if(key == 32) // space
{
myText.SetPosition(100,100,0.75);
}
}