Home / Articles / Adobe Creative Suite / Introducing ActionScript Objects

Introducing ActionScript Objects

  • Sample Chapter is provided courtesy of Peachpit Press.
  • Date: Apr 11, 2003.


  1. Object Primer
  2. Object Sampler
  3. Video Tutorial

Chapter Description

Take advantage of ActionScript's objects, which allow you to perform all sorts of interactive tasks in some very dynamic ways. Also learn how to use objects' properties to manipulate data, colors, sound, dates, and more.

What you'll learn...

How objects are used in Flash Projects

The difference between global objects and classes of objects

About Flash object types and their uses

Just as various objects—for example, computers, cars, stoves, and vacuum cleaners—have unique functions in the physical world, each ActionScript object performs a unique role within Flash. These objects provide a means for working with text, sound, color, dates, and more—in short, allowing you to perform all sorts of interactive tasks in some very dynamic ways.

As you'll soon learn, ActionScript objects resemble their physical-world counterparts in that they have characteristics (or properties), which you can change via a script, and abilities (or methods), which allow them to perform various tasks. The primary advantage of using objects in ActionScript is that they allow you to program and manipulate data, colors, sound, dates, and so on, in a context that makes sense to humans. As you learn more about objects, you'll find that ActionScript's underlying logic becomes clearer as well.

In the text that follows, we'll examine the general structure of objects (that is, how they work), and then take a closer look at some of the specific ActionScript objects you can use to create interactivity in your own projects.

Object Primer

ActionScript objects provide a means of moving graphic elements dynamically, building applications, organizing data, and more. You accomplish these tasks by using or setting object property values and invoking object methods. In this section, we'll show you how properties and methods are used to create interactivity and explain how objects are organized within ActionScript—all of which should provide a strong foundation for the discussion of various objects that follows.


This chapter is not meant to be an exhaustive examination of every ActionScript object.There are far too many (and their capabilities are far too diverse) to cover in a single chapter. Instead, we'll focus here on those objects that are likely to be most useful in your projects. For a more complete survey of objects, pick up a copy of Macromedia Flash MX ActionScripting: Advanced Training from the Source, published by Macromedia Press.


When you look at or touch a physical object, you're naturally aware of the various properties that define its overall form: size, weight, color, age, location, power requirements, and so on. The range of properties objects can possess is as diverse as the objects themselves, and the values assigned to these properties are what make them unique.

For example, a person can be defined by properties such as name, age, height, weight, hair color, and so on. If a person were to be described as an ActionScript object, these property definitions would look like the following:

person.name = "Matt";
person.age = 17;
person.heightInFeet = 6.2;
person.weightInPounds = 180;
person.hairColor = "blond"; 

Although Matt is a pretty well-rounded guy, changing any of these properties will affect either his appearance or the way he interacts with his environment. For example, if we were to change his name to Jill, not only would we likely upset him, we'd also need to change the way we addressed him; the name Matt would no longer elicit a response. Likewise, if we were to change Matt's height, he would no longer be able to reach things that he was able to before, and if we were to alter his hair color, his appearance would change considerably (take my word on this).

In ActionScript, many (though not all) objects have properties. For example, movie clip instances (which are MovieClip objects) have properties such as _rotation, _visible, _x, _y, and so on. The values of these properties define how the movie clip instance appears, and is interacted with, in your project.

Most property values can be set and read (used) by a script; however, others are read-only—which means that scripts can see and use their values, but not set these values. For example, all movie clip instances have a _totalframes property, which represents the total number of frames on that instance's timeline. While a script can use the value of this property (as in myVariable = _totalframes), it cannot set that value during playback, since the number of frames a movie contains is a hard-wired value (that is, it's locked in by Flash during the export process).

In Flash, property values are identified in relation to an object by a dot that separates the object's name from its property. Although you're probably already aware of this functionality, let's briefly review it. If you have a movie clip instance named bigDog, and you want to change its _rotation property, you would use the following syntax:

bigDog._rotation = 45; 

The above line of script will rotate bigDog 45 degrees. Notice that a dot (.) separates the object's name (bigDog) from the property you want to work with ( (_rotation). You would employ a similar syntax when using an object's property value. For example:

if (bigDog._x = your._x){
}else{   gotoAndStop("relax");

In this script, an if statement compares bigDog's _x property value (horizontal location) with the value of your's _x property, and then reacts accordingly.

You'll notice from the script above that an underscore (_) is used in addressing some movie clip instance properties (specifically, those from the Properties book of the Toolbox List window) (Figure 14.1). This is a holdover from earlier versions of Flash, where properties were identified in this manner. However, in Flash MX, many object properties are identified without an underscore. For example:


Figure 14.1Figure 14.1 Properties listed in the Properties book of the Toolbox List window of the Actions panel are the only ActionScript properties identified with underscores.

As we progress through this chapter, we'll show you how you can use different objects' properties to create interactivity.


Methods represent tasks that an object can perform. For example, if you were to look at a dog as an object, its methods would include the abilities to eat, bark, run, play, and sleep. If a dog were an ActionScript object, the syntax for these methods would look like this:


The parentheses that are included in a method are sometimes used to pass it a parameter or set of parameter values, allowing it to act in a unique way, based on those values. For example, if we wanted our dog to eat a particular type of food, we could indicate this in the parentheses, as in the following:


If at a later time we wanted our dog to eat again, but something other than steak, we would once again invoke the eat() method, but pass it a different value, such as:


The method still does the same thing (eats), but what is eaten is different. Herein lies the power of methods: They perform specific tasks, but you can often configure them to perform those tasks using unique values. To give you a better idea of how this works, let's look at a couple of real examples using a movie clip instance. One of the methods available to movie clips gives them the ability to duplicate themselves: This is the duplicateMovieClip() method, which is invoked as follows:

myBankAccount.duplicateMovieClip("playMoney", 1); 

In the above example, we're duplicating the movie clip instance named myBankAc-count, naming the duplicate playMoney, and giving it a depth of 1. Notice in the example how a comma separates multiple parameter values used by the method. Also note that (similar to working with properties), the name of the object (myBankAc-count) and the method invoked are separated by a dot. You can invoke the duplicate-MovieClip() method in any number of ways. Take a look at one other example:

chocolateCake.duplicateMovieClip("goodStuff", 15); 

In this example, we've duplicated the movie clip instance named chocolateCake, given the duplicate an instance name of goodStuff, and a depth of 15. One method, many uses.

Not all methods take parameter values. For example, the stop() action/method doesn't, because its sole purpose is to stop a timeline.

Each type of object has its own unique set of methods—which makes sense given that each object type has a specific purpose and use in your project (Figure 14.2).

Figure 14.2Figure 14.2 Each type of object used in ActionScript has its own unique set of methods.

How Methods Function

If methods seem familiar, it's because they're based on functions (see Chapter 13). In fact, methods are really nothing more than functions that only have meaning in the context of the object type they're associated with.For example,the setVolume() method only has meaning within the context of a Sound object.This bond between function and object is what makes methods different. Note also that while functions are called,methods are invoked,which is really just geek-speak for the same thing.

Flash hides the code that defines methods for built-in ActionScript objects; however, if you were able to view their structure, you'd see that method definitions resemble function definitions. And once you understand how functions work, you can create your own methods or customize existing ones. Although these techniques are beyond the scope of this book, you can learn more about them in Macromedia Flash MX ActionScripting: Advanced Training from the Source, published by Macromedia Press.

Types of Objects

Not all objects are created equal. Some have a global bearing on your project (that is, on your project as a whole), while others let you create instances of them, which you can work with and control individually. In this section, we'll look at both types of objects, exploring their differences and explaining how you can work with each.

Global objects

Within the context of a Flash movie, some objects are global, or unique to the movie as a whole. The mouse, for example, is defined as a global object (Mouse object) because a Flash movie can only contain one mouse (cursor). You can't have more than one mouse, as you can movie clips, text fields, and sounds. Global objects are predefined within Flash, and as such are ready for use at any time. In contrast, objects such as movie clips, text fields, and sounds don't exist in your projects until you create instances of them (see "Objects with Instances" a little later in this chapter).

Flash contains the following global objects:

  • Math
  • Accessibility
  • Key
  • Mouse
  • Selection
  • Stage
  • System

You address these objects directly within ActionScripts, as shown below:


Note the lack of instance names. Because all global objects are unique—that is, only one of each exists in a given Flash movie—instance names have no meaning in the context of global objects.

Object classes

A class of objects represents a group of object instances within your project that share the same basic structure and functionality. For example, all movie clip instances belong to the MovieClip class of objects; all text field instances belong to the TextField class of objects; and so on (Figure 14.3). When an instance of an object is part of a class, it shares the same properties and methods as all other instances of that class.

Figure 14.3Figure 14.3 An object class represents a group of object instances within your project that share the same basic structure and functionality.

For example, all movie clip instances have _rotation and _visible properties, as well as play() and stop() methods, which enable you to control them in various ways. These properties and methods are different than those that exist for instances of the TextField class of objects.

ActionScript contains dozens of object classes, including (but not limited to) the following:

  • Arrays
  • Numbers
  • Strings
  • Dates
  • Sounds
  • MovieClips
  • TextFields
  • XML

With the exception of MovieClip, Button, and TextField instances (which we'll discuss in a moment), all object-class instances are created via what's known as a constructor—a simple piece of ActionScript code that creates an instance of the object class you specify. For an example of this, take a look at the following:

mySound = new Sound(); 

The above line of code creates an instance of the Sound object class named mySound. To give you an idea of the common constructor syntax used to create all such object-class instances, let's take a look at another example:

//create an instance of the Color object
myColor = new Color();
//create an instance of the Date object
myDate = new Date();
//create an instance of the XML object
myXML = new XML(); 

Once an object instance has been created, you can target it for actions in scripts, attach event handler methods to it, or script other interactions with it. Take a look at the following example:

mySound = new Sound()
mySound.loadSound("heyJude.mp3", true);
mySound.onSoundComplete = function(){
   myMovieClip._visible = true;

The first line of the above script creates an instance of the Sound object named mySound. The next line dynamically loads an external MP3 file into this object. The last three lines attach an event handler method to it, so that it will call the unnamed function shown when the sound loaded into it completes its playback. The instance must be created first, in order for either of the other functionalities to work. It's important to maintain this flow as you work with object instances.

You can use one script to create an object instance (such as on a frame) and another (such as on a button) to script its functionality—as long as the instance is created first.

As mentioned above, MovieClip, Button, and TextField object instances are created differently than other object-class instances—that is, without a constructor. This is because these are the only object instances that you create and place directly on the stage. Thus, when you create a text field on the stage, you're actually creating (by default) an instance of the TextField object. Likewise when you place a movie clip on the stage—you're actually creating an instance of the MovieClip object. When creating these instances, you assign them instance names, which allow you to work with and communicate with them via ActionScript.


Object instances are often simply referred to as objects.

Objects are organized in the Toolbox List window in the following groups (Figure 14.4):

  • Core. These objects deal with internal data storage and manipulation.

  • Movie. These objects deal with visual content and system-related information such as movie clips, text fields, the stage, and accessibility.

  • Client/Server. These objects are used for moving data in and out of Flash.

  • Authoring. These objects allow you to create custom actions and components.

Figure 14.4 Figure 14.4 Objects are organized into four groups in the Toolbox List window of the Actions panel: Core, Movie, Client/Server, and Authoring.

2. Object Sampler | Next Section

Adobe Press Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Adobe Press and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Adobe Press products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.adobepress.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020