Create an object from a class 257
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.
Summary of Contents for FLASH 8-FLASH
Page 1: ...Flash Tutorials...
Page 10: ...10 Contents...
Page 12: ...12 Introduction...
Page 42: ...42 Basic Tasks Creating a banner Part 1...
Page 78: ...78 Basic Tasks Creating a banner Part 3...
Page 88: ...88 Basic Tasks Create Accessible Flash Content...
Page 106: ...106 Basic Tasks Create an Application...
Page 116: ...116 Basic Tasks Use Layout Tools...
Page 124: ...124 Basic Tasks Create Symbols and Instances...
Page 134: ...134 Basic Tasks Add Button Animation and Navigation...
Page 144: ...144 Basic Tasks Create a Presentation with Screens Flash Professional Only...
Page 192: ...192 Creating Graphics Applying Gradients...
Page 198: ...198 Creating Graphics Apply Graphic Filters and Blends Flash Professional Only...
Page 224: ...224 ActionScript Use Script Assist mode...
Page 268: ...268 ActionScript Work with Objects and Classes...
Page 270: ...270 Data Integration Overview Flash Professional Only...