About Classes And Object Types; Creating An Object From A Class - MACROMEDIA FLASH MX 2004-LEARNING FLASH Manual

Learning flash
Table of Contents

Advertisement

On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/
Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicActionScript/
finished_files.
Select Window > Panel Sets > Training Layout to configure your workspace.
2.

About classes and object types

A class, also referred to as an object type, is like a blueprint. An object doesn't exist until you create
it, or instantiate it, from a class definition. An object is an instance of a class.
Properties are the characteristics of an object. For example, when you align movie clips, you
change the
and
_x
to a class. A property can either be public, which means it is accessible outside the class, or private,
which means it can be accessed only within the class.
In object-oriented terms, a method is a behavior or procedure that can act on the object. A
hypothetical
throw()
aware of the object and all the properties that it contains and can work on that object.

Creating an object from a class

You'll create an existing class using visual tools (the TextField class) and code (using the
Date class).
Open a new Flash document and change the name of Layer 1 to Text.
1.
In the Text layer, create a dynamic text field and assign it the instance name of currentDate_txt.
2.
Create an Actions layer. With Frame 1 of the Actions layer selected, open the Actions panel.
3.
Create, or instantiate, an object from the Date class, named myDate:
4.
var myDate:Date=new Date();
Create a variable called
5.
var currentMonth:Number = myDate.getMonth();
Trace the value of
6.
trace (currentMonth);
Save and test the document.
7.
You should see a number in the Output panel that represents the month.
The
getMonth()
indexed, meaning the numbering begins at zero rather than one, so the number displayed is
one less than what you would expect.
Close the Output panel and the SWF file window.
8.
114
Chapter 15: Work with Objects and Classes Using ActionScript 2.0
properties of the MovieClip object. A property is a variable that is attached
_y
method on a ball would know the size and weight of the ball. A method is
currentMonth
:
currentMonth
method displays the current month. The
equal to the
getMonth()
getMonth()
method:
method is zero-

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-LEARNING FLASH and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents