Home arrow Flash arrow ActionScript Syntax for Flex Applications
FLASH

ActionScript Syntax for Flex Applications


In this second part of a five-part series that focuses on using ActionScript in Flex applications, you will learn ActionScript's syntax and how to use it with Flex. 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). 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 / 13
May 08, 2008
TABLE OF CONTENTS:
  1. · ActionScript Syntax for Flex Applications
  2. · Declaring Classes
  3. · Variables and Properties
  4. · Variables and Properties continued

print this article
SEARCH DEVARTICLES

ActionScript Syntax for Flex Applications
(Page 1 of 4 )

Understanding ActionScript Syntax

Whether you’re writing ActionScript code inline, in an MXML script, or in a class, you’ll need to understand its basic syntax. The following sections look at the basic elements of ActionScript, such as class syntax, variables, statements, expressions, functions, and objects.

Understanding Packages

The majority of classes are organized into structures called packages. To understand most of ActionScript, you must understand what packages are and how you can work with them.

A package groups together classes so that you can ensure uniqueness of scope. For example, you can have only oneButton class within a scope. If you tried to declare twoButtonclasses in the same scope, there would be a conflict; the compiler wouldn’t know which one to use.

A package allows you to create several classes with the same name by placing them in different scopes. For example, theButtonclass that’s part of the Flex framework (i.e., the button UI component) exists within a package calledmx.controls. When a class is placed within a package, it has what’s called a fully qualified class name. Therefore, the fully qualified class name forButtonismx.controls.Button. That ensures that if you want to create anotherButtonclass in a different package, you can do so without conflicting withmx.controls.Button. For example,mx.controls.Buttonandcom.example.ui.Button(a fictitious class) could exist within the same application without causing a problem.

When classes are in packages, it can be quite cumbersome to have to refer to a class by its fully qualified name. For example, if you want to declare aButtonvariable, you have to use the following code if you wish to use the fully qualified class name:

  var button:mx.controls.Button;

And if you wanted to use the constructor, you’d have to use the following code:

  button = new mx.controls.Button();

Obviously, it’s much more convenient to use the shorthand form of a class name (i.e.,Button). ActionScript allows you to reference a class by the shorthand notation if you first add animportstatement. Animportstatement tells the compiler that you can refer to the class by its shorthand notation from that point forward. The following is animportstatement for theButton class:

  import mx.controls.Button;

You can simply refer toButtonas such from that point forward.

If you import twoButton classes (from different packages) in the same class, you must still refer to them using their fully qualified class names within that class.


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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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