Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Adobe AIR

  • Print
  • + Share This
This chapter is from the book

ActionScript Libraries

Along with the AIR and Flash APIs, and existing JavaScript frameworks, another way to add functionality to your applications is to tie into an ActionScript library. ActionScript, in case you're not familiar with it, is a scripting language commonly used in Flash. But as of version ActionScript 3, it can now be used with Adobe AIR.

ActionScript libraries are compiled as .swf files (Shockwave Format). These can be used in an AIR application after including them as you would any JavaScript file:

<script src="somefile.swf" type="application/x-shockwave-flash"></script>

Note that you should explicitly use the type attribute with a value of application/x-shockwave-flash.

If you're comfortable with JavaScript, learning ActionScript isn't too much of a leap. But even if you never write your own code, you'll likely still use some ActionScript in your AIR applications thanks to servicemonitor.swf. The AIR SDK comes with this one precompiled library and is found in the same SDK frameworks directory as AIRAliases.js. It defines the functionality for detecting network connectivity (which can be used, for example, to see if the user is currently connected to the Internet or not—a valuable piece of information).

To use ActionScript libraries:

  1. Begin a new AIR project in your text editor or IDE.

    The exact steps for doing so are outlined in Chapter 2 and Chapter 3.

  2. Add a new folder named as to your project's directory (Figure 4.6).
    Figure 4.6

    Figure 4.6 The new folder—as—will store the ActionScript library.

    As in the steps for using frameworks, I recommend creating a separate folder in which your ActionScript files will be stored.

  3. Copy the servicemonitor.swf file to the folder created in step 2.

    You'll find servicemonitor.swf in the frameworks folder within the SDK folder (created when you installed the SDK following the instructions in Chapter 2).

  4. Add the following to the head of the main HTML document:
    <script src="as/servicemonitor.swf" type="application/x-shockwave-flash"></script>
    

    If you used a different name for the ActionScript folder (created in step 2), you'll need to change this code accordingly.

  5. Use the ActionScript code as needed in your program.

    You'll see examples of this in Chapter 13, "Networking."

  6. When you build the final application, be sure to include the as folder and the .swf file.

    If you're building the application using the command-line tools (as demonstrated in Chapter 2), the requisite instruction would be something like (Figure 4.7)

    adt -package -storetype pkcs12 -keystore C:\Documents and Settings\Larry Ullman\My
     Documents/MyCert.pfx ActionScript.air application.xml index.html AIRAliases.js as
    
    Figure 4.7

    Figure 4.7 Building the application on Windows using the command-line adt.

    Aptana Studio automatically includes the file as long as it's listed in the project (see Figure 4.5 for an earlier example). With Dreamweaver, make sure you add all the files and folders in the AIR Application and Installer Settings window (see Figure 4.3 for an earlier example).

  • + Share This
  • 🔖 Save To Your Account