Flash
  Home arrow Flash arrow Page 3 - Manipulating Data with ActionScript in Fle...
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

Manipulating Data with ActionScript in Flex Applications
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-05-15

    Table of Contents:
  • Manipulating Data with ActionScript in Flex Applications
  • Expressions
  • Arrays
  • Objects
  • Inheritance

  • 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


    Manipulating Data with ActionScript in Flex Applications - Arrays


    (Page 3 of 5 )

     

    Arrays are sets of data organized by integer indices or keys. ActionScript defines an Array type. New arrays are defined using an Array constructor as part of a new statement (which we’ll talk about in the next section, “Objects”), or using literal notation. The literal notation uses square brackets to create an array. The following creates a new empty array and assigns it to a variable:

      var books:Array = [];

    You can also populate an array by adding a comma-delimited list of values between the square brackets:

      var books:Array = ["Programming Flex 2", "ActionScript 3.0 Cookbook"];

    You can access specific elements of the array using array access notation. The following example retrieves the first element from the array (ActionScript arrays are 0-indexed) and displays it in the console (again, if you are debugging the application):

      trace(book[0]);

    You can also assign values to elements using array access notation, as follows:

      book[2] = "Web Services Essentials";

    Arrays are objects in ActionScript, and they have methods and properties like most objects. It’s beyond the scope of this book to delve into theArrayAPI in depth. However, of theArrayAPI, thelengthproperty andpush()method are the most commonly used. Thelengthproperty returns the number of elements in the array, and it is commonly used with aforstatement to loop through all the elements of an array. Thepush()method allows you to append elements to an array.

    ActionScript arrays are not strongly typed. That means you can store any sort of data in an array, even mixed types. Theoretically, you could store numbers, strings, dates, and even other arrays in an array.

    ActionScript does not have any formal hashmaps or similar types. ActionScript does have anObjecttype, which is the most basic of all object types. Unlike the majority of ActionScript classes theObjectclass is dynamic, which means you can add arbitrary properties toObject instances. Although it is generally better to write data model classes than to store data inObject instances using arbitrary properties, there are cases when it is useful to use anObject instance as a hashmap/associative array. The following example creates anObjectinstance and assigns several keys and values:

      var authorsByBook:Object = new Object();
      authorsByBook["Programming Flex 2"] = "Chafic Kazoun,Joey Lott";
      authorsByBook["ActionScript 3.0 Cookbook"] = "Joey Lott,Keith Peters,Darron Schall";

    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 1 Hosted by Hostway
    Stay green...Green IT