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


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.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as