Flash
  Home arrow Flash arrow Page 2 - 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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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 / 4
    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
     
     
    ADVERTISEMENT


    ActionScript in Flex Applications - Using ActionScript


    (Page 2 of 4 )

    When you want to use ActionScript within Flex, you have four basic options for where to place the code:

    1. Inline within MXML tags
    2. Nested within MXML tags
    3. In MXML scripts
    4. Within ActionScript classes

    The preceding lists the techniques for working with ActionScript code, from the simplest to the most complex form. We’ll look at each of these techniques in the following sections.

    Inline ActionScript

    Inline ActionScript appears within MXML tags. Believe it or not, you’ve already seen several examples of this in Chapter 3. Inline event handling and data binding using curly brace syntax necessarily uses basic ActionScript. The following example uses ActionScript to display an alert dialog box when the user clicks on a button:

      <mx:Button id="alertButton" label="Show Alert"
                 click="mx.controls.Alert.show('Example')" />

    In this example, the text assigned to theclickevent handler attribute is ActionScript code, which calls ashow()method of an ActionScript class calledAlert.

    The next example uses data binding:

      <mx:VBox>
       
    <mx:TextInput id="input" />
       
    <mx:Text id="output"
    text="{input.text}" />
      </mx:VBox>

    This example uses the ActionScript expressioninput.textto evaluate thetextproperty value for theinputobject (the text input control).

    Inline data binding represents the most limited use of ActionScript, because it can evaluate only one expression. For instance, the preceding example evaluates the expressioninput.text. You could use a more complex expression, such as the following:

      <mx:VBox>
       
    <mx:TextInput id="input" />
       
    <mx:Text id="output" text="{'User input: ' + input.text}" />
     
    </mx:VBox>

    This example concatenates the stringUser input:with the user input from the text input control. You can also create even more complex expressions using inline data binding.

    Inline event handlers allow you to write more complex ActionScript that can consist of several statements. ActionScript statements generally end with semicolons. The following example illustrates a button with slightly more complex event handler code, consisting of two expressions:

      <mx:Button id="alertButton" label="Show Alert" click="mx.controls.Alert.
      show('Example');alertButton.x += 40;" />

    This example first displays an alert dialog box. It then moves the button to the right by 40 pixels. Although you can string together many statements (as in this example), it is very uncommon. It’s not difficult to understand why this would be. Rather simply: the code is difficult to read and manage when you try to use several inline statements in that fashion. If an event handler needs to run several statements, it is far more common to simply call a function. We’ll look more at functions in the next section, and then later in the chapter, in the “Methods ” 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

    - 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
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek