• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 22. ActionScript: Work with Obje... > Create an object from a class

Create an object from a class

You’ll create an existing class using visual tools (the TextField class) and code (using the Date class).

1.
Open a new Flash document and change the name of Layer 1 to Text.

2.
In the Text layer, create a dynamic text field and assign it the instance name of currentDate_txt.

3.
Create an Actions layer.

With Frame 1 of the Actions layer selected, open the Actions panel.

4.
Create, or instantiate, an object from the Date class, named myDate:

var myDate:Date=new Date();

5.
Create a variable called currentMonth equal to the getMonth() method:

var currentMonth:Number = myDate.getMonth();

6.
Trace the value of currentMonth:

trace (currentMonth);

7.
Save and test the document.

You should see a number in the Output panel that represents the month.

The getMonth() method displays the current month. The getMonth() method is zero-indexed, meaning the numbering begins at zero rather than one, so the number displayed is one less than what you would expect.

8.
Close the Output panel and the SWF file window.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint