develop wherever and whenever you want...
Docs > Window Class Reference

Window Class Reference

Summary 
The Window class is represented by a single object window. This provides a number of utility functions for handling timers, render functions, animation, and sound support. number setInterval(function,delay) 
void clearInterval(id) 
void beginAnimation(delay,duration[,curve]) 
void commitAnimation() 
void onAnimationComplete(handler) 
number createSound(file) 
void playSound(id) 
void closeSound(id) 
void requestAnimationFrame(handler) 

Example 
r = new View(); 
l = r.createLabel(300,200); 
window.beginAnimation(0,2); 
l.setFrame(r.width-300,200,300,200); 
count = 0; 
function tick() { 
l.setText(count); 
count++; 

window.setInterval(tick,200); 
function beep() { 
id = window.createSound("tap.aif"); 
window.playSound(id); 

window.onAnimationComplete(beep); 
window.commitAnimation(); 
document.wait(); 


setInterval 
Creates a timer that will call back repeatedly after a delay amount

number setInterval(handler,delay)

Parameters 
handler - function to call when the duration expires delay - delay in milliseconds

Return Value 
Number id associated with the timer created.

Notes 
The function will be called repeatedly until clearInterval() is called. Multiple timers can be created using setInterval(), each will have a unique id returned. Please note that the program should block on a document.wait() to ensure that timer events are dispatched and that the program doesn't exit immediately.


clearInterval 
Stops a timer given its id.

void clearInterval(id)

Parameters 
id - number, id of timer created using setInterval

Return Value 
none

Notes


beginAnimation 
Start an animation block. All view related changes (setFrame, setBackgroundColor, ...etc.) will be interpolated within the animation on a given curve.

void beginAnimation(delay,duration[,curve])

Parameters 
delay - number of seconds to delay before starting the animation duration - duration of the animation in seconds or fractions of seconds curve - optional string controlling the curve used for animation value can be "linear", "easeIn", or "easeOut". 
Return Value 
none

Notes 
Default curve is linear animation. Please note that the animations do not actually begin until commitAnimation is called.


commitAnimation 
Begin animating all views that changed between beginAnimation and commitAnimation.

void commitAnimation()

Parameters 
none

Return Value 
none

Notes 
If this method is not called, no animations are performed. Also note that the application must be blocked on document.wait() for animations to process.


onAnimationComplete 
Sets a function to call when an animation completes

void onAnimationComplete(handler)

Parameters 
handler - function to call when animation is complete

Return Value 
none

Notes 
This allows chaining of animation sequences since the called function can start a new animation using beginAnimation / commitAnimation and attach another handler and so on...


createSound 
Create a sound from a file (or built-in) that can be used to play the sound

number createSound(file)

Parameters 
file - file and optional path to a sound file to play

Return Value 
Number id of the sound that can then be passed to playSound or closeSound.

Notes 
The file and path are relative to the folder of the current JavaScript file. If the file is not found, it is searched for as a file name for one of the built-in sounds in Jasic and that is returned if found.


playSound 
Play the sound

void playSound(id)

Parameters 
id - number sound id to play

Return Value 
none

Notes 
The sound is only played once with each call to playSound.


closeSound 
Close the associated sound to free up memory resources.

void closeSound(id)

Parameters 
id - number id of sound to play

Return Value 
none

Notes 
Please note that playSound is asynchronous, so if closeSound is called immediately after playSound, the sound will not play since it would possibly get closed before play commences.


requestAnimationFrame 
Register a function to be called at 60 frames per second (or as close as possible to that)

void requestAnimationFrame(handler)

Parameters 
handler - function to call at 60 calls per second (or close to that)

Return Value 
none

Notes 
This powerful method is typically used in WebGL applications to render content repeatedly. Please note that the call frequency of this function is not guaranteed to be 60FPS since there are delays in dispatching calls and that render time can consume CPU or GPU time causing a lower frame rate.