SunQuest
 
       Flash
  Home arrow Flash arrow Page 3 - ActionScript in Flex Applications
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

ActionScript in Flex Applications
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-05-01

    Table of Contents:
  • ActionScript in Flex Applications
  • Using ActionScript
  • Nested ActionScript
  • MXML and ActionScript Correlations

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    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.

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming Flex 2," published by...
     

    Buy this book now. This article is excerpted from chapter four of the book Programming Flex 2, written by Chafic Kazoun and Joey Lott (O'Reilly, 2007; ISBN: 059652689X). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks
    - Building Preloaders
    - Fun Things to Do with Movie Clips in Flash MX
    - Referencing Movie Clips in Flash MX


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway