SunQuest
 
       Flash
  Home arrow Flash arrow Page 4 - Object-oriented ActionScript
IBM developerWorks
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 
 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

Object-oriented ActionScript
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2004-08-30

    Table of Contents:
  • Object-oriented ActionScript
  • Key Object-Oriented Programming Concepts
  • Object Creation and Usage
  • Encapsulation and Datatypes
  • Inheritance, Packages, Compilation
  • Starting an Objected-Oriented Application
  • An Example Website

  • 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&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Object-oriented ActionScript - Encapsulation and Datatypes


    (Page 4 of 7 )

    Objects are said to encapsulate their property values and method source code from the rest of the program. If properly designed, an object’s private properties and the internal code used in its methods (including public methods) are its own business; they can change without necessitating changes in the rest of the program. As long as the method names (and their parameters and return values) stay the same, the rest of the program can continue to use the object without being rewritten.

    Encapsulation is an important aspect of object-oriented design because it allows different programmers to workon different classes independently. As long as they agree on the names of the public methods through which they’ll communicate, the classes can be developed independently. Furthermore, by developing a specification that shows the publicly available methods, the parameters they require, and the values they return, a class can be tested thoroughly before being deployed. The same test code can be used to reverify the class’s operation even if the code within the class is refactored (i.e., rewritten to enhance performance or to simplify the source code without changing the previously existing functionality).

    In Chapter 4, we’ll learn how to use the private modifier to prevent a method or property from being accessed by other parts of a program.

    Datatypes

    Each class in an object-oriented program can be thought of as defining a unique kind of data, which is formally represented as a datatype in the program.

    Note: A class effectively defines a custom datatype.

    You are probably already familiar with custom datatypes defined by built-in Action-Script classes, such as the Date class. That is, when you create a Date object using new Date( ), the returned value contains not a string or a number but a complex datatype that defines a particular day of a particular year. As such, the Date datatype supports various properties and methods uniquely associated with dates.

    Datatypes are used to impose limits on what can be stored in a variable, used as a parameter, or passed as a return value. For example, when we defined the speed property earlier, we also specified its datatype as Number (as shown in bold):

    // The expression ":Number" defines speed's datatype.
    public var speed:Number;

    Attempts to store a nonnumeric value in the speed property generate a compile-time error.

    If you test a movie and Flash’s Output panel displays an error containing the phrase “Type mismatch,” you know that you used the wrong kind of data somewhere in your program (the compiler will tell you precisely where). Datatypes help us guarantee that a program isn’t used in unintended ways. For example, by specifying that the datatype of speed is a number, we prevent someone from unintentionally setting speed to, say, the string “very fast.” The following code generates a compile-time error due to the datatype mismatch:

    public var speed:Number = "very fast"; // Error!
                            // You can't assign a String to a
                            // variable whose type is Number.

    We’ll talk more about datatypes and type mismatches in Chapter 3.

    Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit the O'Reilly Network http://www.oreillynet.com for more online content.

    More Flash Articles
    More By O'Reilly Media


       · This is an excellent article. It has not only given me a much needed and easy...
       · I noted that the code for the Tomagotchi exercise and introduction to...
     

    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 1 hosted by Hostway