Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here








 

Google

Search WWW   
FlashAdvisor.com

 Home > Tutorials  > Dynamic Content

Flash Javascript API > An Introduction

Author: Saumitra | Email


Advertisement


(Applicable for Flash version > Flash MX 2004/Flash MX 2004 Pro)

Introduction
With the release of Flash MX 2004, a new arena was opened up for Flash Programmers called the Flash Javascript API. The programmers can now extend the Flash authoring environment itself to execute customized tasks making life much easier.

Imagine doing the following:

1. Organizing the library into folders like "graphics", "movies", "buttons", "audio" and "components" and putting all the items in the library into corresponding folders on a click of a button.
2. Saving all open Flash documents at regular intervals to avoid data loss.
3. Creating a new tool in the Flash toolbox for selecting "fills" only.
4. Converting all static/dynamic textboxes in a .fla file into dynamic textboxes with sequential instance names and generating an xml file out of it.
5. Creating a text effect on a selected text box just like the ones created by 3rd party tools like Swish or Flax.
All this and such "smart" tasks are now possible using the Flash Javascript API in the authoring mode.
Before getting our hands dirty on programming for the JSAPI lets see how it is configured. The "script" used to perform the specific tasks is saved as a .jsfl file.

The JSFL file:
There are 2 ways to create a jsfl file:

1. Use the "History" panel and saving the 'recently' performed commands.
2. Use Flash MX 2004 Pro JSFL editor or any text editor like SE|PY actionscript editor or even good old Notepad.

Once the code is written the file can be saved anywhere. To call a saved jsfl file do the following:
1. Open the Commands Menu as seen below:



Figure 1.1

2. Choose the "Run Command" button.
3. Using the browse file dialog box select the appropriate jsfl file.

If you want you "command" to appear in the Commands Menu itself like the "browse", "delete", "key_frame" commands seen above in Figure 1.1, you must save the jsfl file at a specific location(depending on the OS) as mentioned below:

Windows 2000 or Windows XP:
C:Documents and SettingsuserLocal Settings Application DataMacromedia Flash MX2004languageConfigurationCommands

Windows 98:
C:WindowsApplication DataMacromediaFlash MX 2004language ConfigurationCommands

Mac OS X:
Hard Drive/Users/userName/Library/Application Support/Macromedia/Flash MX 2004/language/Configuration/Commands
Flash JSAPI can be accessed through the Flash object which is the top level object. It represents the Flash Authoring environment. The fl object being the top level object is always available to the JSAPI as long as the authoring environment is open.

In a jsfl file it is referred to as "flash" or simply "fl".
For example, following statement will open the "Browse for file" dialog box:

fl.browseForFileURL();


The Flash Object
The flash object contains the following child objects:
componentsPanel object
This object corresponds to the Components panel in the Flash authoring environment. You can use this to add a component from the components panel to the Flash Document.

Document object
This is the most commonly used object in the jsfl files. This represents the stage of the flash document. Thus many critical methods are available for this object.

drawingLayer object
This object is used while creating extended tools. Methods for temporary onscreen drawing while the mouse is pressed are a part of this object.

Effect object
The effect object represents the instance of a Timeline effect.

Math object
The Math object provides methods for common mathematical operations.

outputPanel object
This object corresponds to the Output panel in the Flash authoring environment. Similar to "Trace" in the test Movie mode, this object can be used for diagnostic purposes.

Tools object
fl.tools is an object that has a toolObjs property. The toolObjs property is an array of toolObj objects. Each toolObj object represents a tool in the Flash Tools panel.

ToolObj object
Use fl.tools.toolObjs to retrieve an array of all tool objects (see tools.toolObjs); use fl.tools.activeTool to access the currently active tool object (see tools.activeTool). The ToolObj can also be used to create new tools or extending the existing tools.

XMLUI object
This object is used to create custom UI to perform specific actions based on user response. For example, the UI will provide a dropdown menu to choose a text affect that should be applied to a selected textbox.

Other Objects
There are several other objects in Flash JSAPI which are used to create the jsfl files. To name a few, the "Text", "Library", "Timeline", "Layer", "Symbol", "Item" etc. Each of these are very critical and can be used completely to control the Flash Authoring environment and customizing it for smarter use.
The Flash JSAPI also provides 'C' level extensibility. Using this one can use a custom C code bundled into a dll file saved in an appropriate directory. This is typically useful in performing fast calculations or complex algorithms that are difficult to create in Flash.

Detailing each of the objects and C level extensibility is beyond the scope of this tutorial.

Thus, the Flash MX 2004 JSAPI can be used innovatively to make routine tasks automated to make life easier. You can refer to other JSFL tutorials on this website to get hands on with JSFL.

| 1 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

1 user online