Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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

If you're experienced with ActionScript—or even JavaScript—JSFL won't be a stretch. There's just a few idiosyncrasies you need to know about. Find out how to write and execute your own JSFL scripts.


advertisement
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\ <user>\Local Settings\Application Data\Macromedia\Flash MX 2004\ <language>\Configuration\Commands\ Windows 98: C:\Windows\Application Data\Macromedia\Flash MX 2004\ <language>\Configuration\Commands\ Macintosh 0SX: Hard Drive/Users/ <username>/Library/Application Support/Macromedia/Flash MX 2004/ <language>/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.



Guy Watson (or FlashGuru as he is also known) has been an active, well recognized figure in the Flash community for four years, supporting the community with tutorials, source files, forum moderation, and running his own Flash resource Web site, FlashGuru's MX 101. Guy was one of two developers who created the ever popular, award winning zoom interface for Relevare and now works for the leading entertainment company Endemol UK, the creative force behind reality television, producing programs such as Big Brother and The Salon. Guy now spends most of his time developing Flash games and applications for high profile clients such as Channel 5 Television, Ladbrookes, and UK Style.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date