Flash
  Home arrow Flash arrow Page 2 - ActionScript Syntax for 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 
Moblin 
IBM® developerWorks 
Sun Developer Network 
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 Syntax for Flex Applications
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-05-08

    Table of Contents:
  • ActionScript Syntax for Flex Applications
  • Declaring Classes
  • Variables and Properties
  • Variables and Properties continued

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    ActionScript Syntax for Flex Applications - Declaring Classes


    (Page 2 of 4 )

    Next, let’s look at the basic syntax and structure of a class. At a minimum, all ActionScript 3.0 classes consist of the following elements:

    1. Class package declaration
    2. Class declaration

    Additionally, classes almost always also haveimportstatements.

    Creating class files

    Each class must be defined in its own file. (There are a few unique exceptions, but in most practical cases, a class must be defined in its own file.) The name of the file must be the same as the name of the class it contains, and the file must use the .as file extension. For instance, if you want to define an Example class, you must create a file named Example.as.

    Package declarations

    The syntax for all ActionScript 3.0 classes begins with a package declaration. As discussed earlier in this chapter, packages are used to organize classes. A package name in ActionScript corresponds to the directory structure within which the ActionScript file is stored. Each directory and subdirectory is delimited by a dot (.) in a package name. For example, if a class is stored in the example subdirectory of a com directory, the package name would becom.example. A class’s package declaration uses thepackagekeyword followed by the package name. Opening and closing curly braces, which contain anyimportstatements and class declarations, follow thepackagedeclaration. The followingpackagedeclaration says that the enclosed class exists within thecom.examplepackage. This also means that the file must exist within a com/example directory relative to one of the source path directories:

      package com.example {
       
    // Import statements go here.
       
    // Class declaration goes here.
      }

    It’s considered a best practice to place all class files within packages with the possible exception of main class files when creating ActionScript 3.0-only (non-Flex) applications.

    Import statements

    As noted earlier, import statements should appear within thepackage declaration, but not within the class declaration. (Technically,importstatements can be placed anywhere, but by convention, they should be placed within thepackagedeclaration, but not in the class declaration.) You mustimportany and all classes you intend to use.

    ActionScript 3.0 classes don’t automatically import classes. The following example imports theURLLoaderandURLRequestclasses from the Flash Player API:

      package com.example{
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        // Class declaration goes here.
     
    }

    Class declaration

    All public ActionScript 3.0 classes placed within package declarations must be declared using thepublickeyword, followed by theclasskeyword and the name of the class. Opening and closing curly braces then follow, within which you place the class definition. Class names always start with initial capital letters by convention. The following example declares anExampleclass in thecom.examplepackage:

      package com.example {
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        public class Example {
         
    // Class code goes here.
        }
      }

    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