JavaScript

From Director Online Wiki
Jump to: navigation, search

A scripting language developed by Netscape, originally called LiveScript, to add interactivity to websites. Not to be confused with Java from Sun Microsystems! It has grown in popularity ever since, becoming adopted for much wider purposes than originally intended.


For more information, see:

WikiPedia on JavaScript [[1]]

As of Director MX 2004, JavaScript is available as a second scripting language alongside Lingo. In this first release, JavaScript is not viable as a complete replacement for Lingo, due to the occasional missing feature. However there are many advantages to JavaScript syntax, perhaps the single most important one being support for regular expressions without the need for a 3rd party Xtra.

Any given script can use JavaScript or Lingo syntax, but not both. You need to specify the language via the language drop-down in the authoring environment. Once you have created your script it may call any other script in your project, regardless of which language either script is written in.

There are some problems in this version, however. It is currently not possible for a Lingo script to instantiate a JavaScript object using the normal new syntax. In JavaScript you can instantiate an object like so:


JavaScript Object Example

   function myClass( aProperty )
   {
      this.pProperty = aProperty;
   }
   myObject = new myClass();


However, you cannot use new in this way in Lingo. Instead, you must use a JavaScript wrapper function to create your objects, or create your objects in a slightly different way. For Example:

A JavaScript Wrapper Function

   function spawmMyClass( aProperty )
   {
       return new myClass();
   }


An Alternative Method

   function myClass( aProperty )
   {
       var obj = new Object();
       obj.pProperty = aProperty;
       return obj;
   }