![MACROMEDIA FLASH MX 2004-LEARNING FLASH Скачать руководство пользователя страница 115](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-learning-flash/flash-mx-2004-learning-flash_manual_3379009115.webp)
Creating a custom class
115
Modify your script
You’ll modify your script to compensate for the zero indexing.
1.
Add
+1
to the value when you create
currentMonth,
and test your document to be sure the
expected month number appears. That line of script should read as follows:
var currentMonth:Number = myDate.getMonth()+1;
2.
Comment the trace statement:
//trace (currentMonth);
3.
Below the trace statement, set the
autoSize
property of your text box to
true
:
currentDate_txt.autoSize = true;
4.
Use the text property of your text box to display today’s date in the form Today is mm/dd/yyyy.
Use the
currentMonth
variable you have already created, plus the
getDate()
and
getFullYear()
methods of the Date object:
currentDate_txt.text="Today is "+curre"/"+ myDate.getDate() + "/
"+myDate.getFullYear();
5.
Verify that your script appears as follows:
var myDate:Date=new Date();
var currentMonth:Number = myDate.getMonth()+1;
//trace (currentMonth);
currentDate_txt.autoSize = true;
currentDate_txt.text="Today is "+curre"/"+ myDate.getDate() + "/
"+myDate.getFullYear();
6.
Save and test the document. The current date should appear in the SWF file window.
Note:
An example finished file of the document you just created, named handson1.fla, is located in
your finished files folder. For the path, see
“Set up your workspace” on page 113
.
Creating a custom class
While ActionScript includes many classes of objects, such as the MovieClip class and the Color
class, there will be times when you need to construct your own classes so you can create objects
based on a particular set of properties or methods.
To create a class that defines each of the new objects, you create a constructor for a custom object
class and then create new object instances based on that new class, as in the following example:
Note:
The following ActionScript is an example only. You should not enter the script in your lesson
FLA file.
function Product (id:Number, prodName:Name, price:Number)
{
this.id:Number = id;
this.prodName:String = prodName;
this.price:Number = price;
}
Содержание FLASH MX 2004-LEARNING FLASH
Страница 1: ...Learning Flash...
Страница 8: ...8 Contents...
Страница 34: ...34 Chapter 3 Write Scripts with ActionScript...
Страница 54: ...54 Chapter 6 Create a User Interface with Layout Tools...
Страница 62: ...62 Chapter 7 Draw in Flash...
Страница 68: ...68 Chapter 8 Create Symbols and Instances...
Страница 76: ...76 Chapter 9 Add Animation and Navigation to Buttons...
Страница 104: ...104 Chapter 13 Add Interactivity with ActionScript...
Страница 112: ...112 Chapter 14 Create a Form with Conditional Logic and Send Data...
Страница 122: ...122 Chapter 15 Work with Objects and Classes Using ActionScript 2 0...