|
|
Using Creativyst® JavaScript Interactive
JavaScript Interactive lets you interactively write and run JavaScript code,
giving you a page, some DIV elements and some form elements to use in your
scripts.
You may use any of the functions from the Creativyst® Browser Tools library of
functions, as well as functions from a special set provided by the
JavaScript InterActive itself.
Some Interactive functions are provided for convenience in writing output
to the form functions.
- ToOut0n(txt)
Where "n" is a number from 1 to 3, writes text
to on of the output fields in Form01 labeled "Out01".
through "Out03" respectively.
- ClrOut0n()
Clears the respective output field on Form01.
Note that you may just as easily write:
document.forms.Form01.Out01.value = Out01Txt;
But the ToOut...() functions are provided for convenience. They
also work with the clear functions to make the output fields
look like teletypes (though this is more useful on the textarea
than on the small fields).
Other functions and variables are provided to allow you to do things
JavaScript Interactive would normally not let you do.
- Btn01Val
This variable is bumped every time the button (Btn01) is pushed.
You may test it and reset it as you see fit. Some of you may be
wondering how you can run a one-shot JavaScript and be able to
test the button press. Read on.
- UserNum01 and UserString01
Two persistent strings you can store values in without losing
them every time your script ends. You'll understand why
these are needed next.
- LoopSecs(seconds)
Normally your script is evaluated once and returns. Because
of this, you can't use the setTimeout() function since
whatever function you set it to call will be long gone
before the timer runs out. The reason for this, as stated
is that you script, along with all the functions it contains,
is evaluated once, and then goes away. LoopSecs() lets
you keep your script going so you can do things over time. It
does this by running all the code after it over and over in
a loop. It will loop through your code continously for the
number of seconds you specify.
The code before it will only be run once when you first hit
the run button. For this reason, LoopSecs() will
often be the first function called at the top of your code.
There are times though, when you'll want to run some
setup code before the code that loops. e.g.
/*
* Loop Secs() example code
* (Cut and paste this into
* the code box to test).
*/
ClrOut01();
ClrOut02();
Btn01Val = 0;
/*
* Everything above the call
* is run ONCE when the 'RUN'
* button is first pushed.
*
*/
LoopSecs(30);
/* Everything from here
* down is run continuously
* for the number of seconds
* specified in the LoopSecs(parm).
*
* Important: Don't put the
* word: 'LoopSecs' in a comment
* above the call, or it will
* try to run everything below
* the point where it shows up
* in the comment string.
*
*/
MainProc();
function MainProc()
{
if(Btn01Val) {
SendMsg("Pushed");
Btn01Val = 0;
}
}
function SendMsg(txt)
{
var t = new Date();
var tm = t.toGMTString();
var msX;
var msY;
msX = MouseX(); // from browser tools
msY = MouseY();
tm = tm.substr(17,8);
ToOut01( txt +
": " +
tm +
" msX:" +
msX +
" msY:" +
msY +
"\n" );
}
|
|