Home arrow Flash arrow Page 3 - ActionScript in Flex Applications
FLASH

ActionScript in Flex Applications


If you want to create a fairly sophisticated program in Flex, you will need to use ActionScript. If you've never used the two languages together, this five-part series gets you started. It is excerpted from chapter four of the book Programming Flex 2, written by Chafic Kazoun and Joey Lott (O'Reilly, 2007; ISBN: 059652689X). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 4 stars4 stars4 stars4 stars4 stars / 8
May 01, 2008
TABLE OF CONTENTS:
  1. · ActionScript in Flex Applications
  2. · Using ActionScript
  3. · Nested ActionScript
  4. · MXML and ActionScript Correlations

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
ActionScript in Flex Applications - Nested ActionScript
(Page 3 of 4 )

You also can nest ActionScript code within MXML tags. Just as you can nest values for most properties you can nest the values (ActionScript) for event handlers. You must place the code within a CDATA block. Here’s an example:

  <mx:Button>
    <mx:click>
      <![CDATA[
        mx.controls.Alert.show("Example");
      ]]>
    </mx:click>
  </mx:Button>

MXML Scripts

The second way to add ActionScript code to an application is to place it within an MXML script. An MXML script appears in an MXML document within a Script element:

  <mx:Script>
  </mx:Script>

Since ActionScript code may use special characters otherwise interpreted by the MXML compiler, you must place ActionScript code withinScripttags and also within aCDATA block, as in the following example:

  <mx:Script>
  <![CDATA[

    import mx.controls.Alert;

    private function example():void {
      Alert.show("Example");
    }

  ]]>
  </mx:Script>

You can optionally place ActionScript code blocks in separate files, and you can embed them in a script block using thesource attribute of aScripttag:

  <mx:Script source="code.as" />

Within MXML scripts, you can import classes and declare properties and methods. We discuss each of these in more detail in the “Understanding ActionScript Syntax” section, later in this chapter.

Classes

Classes are the most sophisticated and powerful use of ActionScript. Although it’s not wrong to use inline code and MXML scripts, it’s generally advisable to place the majority of ActionScript code within ActionScript classes.

ActionScript class code exists within separate documents, apart from the MXML application and component documents. ActionScript class files are text files that use the file extension .as. We’ll talk more about creating classes later in this chapter, in the “Declaring Classes” section.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials