devxlogo

Extending Flash MX 2004, Part 2: Using Classes and Scripts in JSFL

Extending Flash MX 2004, Part 2: Using Classes and Scripts in JSFL

n this article I will discuss the similarities and differences between ActionScript and JSFL. We will also briefly show you how to write your own JSFL scripts and how to execute them.As with ActionScript, JSFL has a set of predefined classes, containing methods and properties:

  • Array
  • Boolean
  • Date
  • Function
  • Math
  • Number
  • Object
  • RegExp
  • String

ActionScript coders will notice one extra class, the RegExp class. No, that isn’t a mistake; you can use regular expressions in JSFL!

In JSFL, as in ActionScript, every string is an instance of the String class, every array is an instance of the Array class, every number is an instance of the Number class, etc. Which means that strings, numbers, arrays, booleans, objects, etc., are treated in exactly the same way as they are in ActionScript

All Strings have the usual String methods: ‘substr,’ ‘charAt,’ ‘indexOf,’ etc. All Arrays have the usual Array methods: ‘splice,’ ‘pop,’ ‘push,’ and so on.

So for example, you can write:

myStr="A,B,C,D";	bits=myStr.split(","); //use a string method

Or:

myStr="abcd";	myStrLen=myStr.length; //get a string property

In either JSFL or ActionScript the above code snippets produce the same result. For a complete list of each class’s available methods and properties refer to the Netscape JavaScript API documentation.

Top-Level Properties and MethodsJSFL also contains some top-level functions. These are functions that are not related to any particular object or class and thus can be used anywhere in your scripts, as is.

  • encodeURI
  • decodeURI
  • eval
  • Infinity
  • isNaN
  • Number
  • parseFloat
  • parseInt
  • alert

Figure 1. New Document: New Document: File > New > Flash JavaScript File, creates a blank JSFL document in the Flash MX 2004 Authoring Tool ready for editing.

Writing a JSFL Script
You create a JSFL script like you would an external ActionScript file. Using your favorite script editor, you write your JSFL code, then you save the file with a .jsfl extension. You can call the file whatever you like as long as it has the correct file extension.

The Flash MX 2004 Authoring Tool has a built in JSFL Script Editor, which is the same as the ActionScript Editor. You can use it to create a new JSFL script by opening the File menu and then selecting New ?> Flash JavaScript File (see Figure 1).

You can also open JSFL scripts for editing in Flash MX 2004. Naturally your JSFL script will automatically open for editing in the JSFL Script Editor. To edit a JSFL script in Flash MX 2004, open the File menu and then select Open. From there, navigate through your local machine to find the correct JSFL script to edit.

Figure 2. Purpose: Rollover a particular method or property for a brief explanation of its purpose.

As with the ActionScript Editor, the JSFL Script Editor also contains a list of every object and each object’s available methods and properties along the left-hand side. This does come in very handy, as there are a lot of them to remember. Rollover a particular method or property on the left-hand side and you will get a tool tip which will briefly explain what that particular method or property does. The JSFL Script Editor also has syntax highlighting and code hinting.

Executing a JSFL Script
To execute a JSFL script, the Flash MX 2004 IDE must be open. The simplest form of a Flash extension, the Command, has its own special place in the Flash MX 2004 IDE. That is the Commands menu:


Figure 3. The Commands Menu: Run Command from the Commands menu to execute your scripts.
 
Figure 4. My JSFL Scripts: The Commands menu will show your personal JSFL scripts. Select a name to execute the script.

When you select Run Command from the Command menu, you can locate a JSFL script to execute. The Commands menu displays three default options, shown in Figure 3, but it also adds a new option for each JSFL script. This new option is contained within a special Commands directory in the Flash MX 2004 Configuration folder. The location differs with different operating systems:

Windows XP or Windows 2000:C:Documents and Settings Local SettingsApplication DataMacromediaFlash MX 2004 ConfigurationCommandsWindows 98:C:WindowsApplication DataMacromediaFlash MX 2004 ConfigurationCommandsMacintosh 0SX:Hard Drive/Users/ /Library/Application Support/Macromedia/Flash MX 2004//Configuration/Commands/ 

So, if you place your JSFL scripts in this directory, you can execute them directly from the Commands menu, by selecting the name of your script file from the list of options.

As shown in Figure 4, I presently have four JSFL scripts located in my Configuration/Commands directory, with the following filenames:

  • Batch Run.jsfl
  • Convertor.jsfl
  • Save Copy As.jsfl
  • Test.jsfl

When a JSFL script is executed all functions that are called update the state of a particular element in a Flash document immediately, which differs from ActionScript execution. For example in ActionScript, if you move a Movieclip across the stage in a for loop, you would only see the final state of the loop, as the stage is not updated until the ActionScript has been executed. However, if you were to call the ‘deleteLayer’ function of a timeline object in JSFL inside of a for loop, the layer is immediately deleted and the authoring environment will refresh to display the new state of the timeline before the code after the for loop is executed.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist