Ahh, Classes.
Unfortunetly I do not have the hand out in front of me, and the instructor is smart enough to keep nothing online. But I finished the homework and will do my best to explain whats going on.
To start off we created an Actionscript project.
We created a Custom Class called
InventoryItem
The assigment was to take the "author" value and turn it into its own class, that will contain author information such as. First name, last name, and birth date.
To do this I created a new class called
AuthorInformation
This class contains 3 variables called
private var _nameFirst: String;
private var _nameLast: String;
private var _birthDate: String;
In my public function I give the AuthorInformation the correct String values
public function AuthorInformation(nameFirst:String, nameLast:String, birthDate:String){
_nameFirst = nameFirst;
_nameLast = nameLast;
_birthDate = birthDate;
}
Then I set up a function for each variable that will return my String
public function getAuthorNameFirst():String{
return _nameFirst;
}
public function getAuthorNameLast():String{
return _nameLast;
}
public function getAuthorBirthDate():String{
return _birthDate;
}
}
}
Next In my InventoryItem class, I change author from String to the correct data type.
Which happens to be my New Class!
public class InventoryItem{
private var _quantity:Number;
private var _productName:String;
private var _author:AuthorInformation;
And I make sure that all my _author variables, are of AuthorInformation data type!
Get that?
Great, thats done. Now to actually set values within my AS project.
So
First I create my inventoryItem variable
which is of What DataType???
var author3:AuthorInformation = new AuthorInformation("Allen","Ginsberg","12/25/75");
Now I enter all my Values
nameFirst
nameLast
birthDate
You getting this???
Next I create an inventoryItem Variable, which is of my InventoryItem class
var inventoryItem_3:InventoryItem = new InventoryItem(?,?,?);
Now my values
which are...
private var _quantity:Number;
private var _productName:String;
private var _author:AuthorInformation;
*\Notice that
quanity is a number
productName is a string
and author is...???
of my AuthorInformation Class
So what would my values be
quantity is 225
productName is howl
and my AuthorInformation???
Well I declared all that in a variable called???
var author3:AuthorInformation = new AuthorInformation("Allen","Ginsberg","12/25/75");
var inventoryItem_3:InventoryItem = new InventoryItem(225, "Howl", author3);
You getting this?
Awesome thats it. Its done?! WTFUNK!!!
Lets trace!
trace ("Title: " + inventoryItem_3.getProductName());
trace ("Quantity: " + inventoryItem_3.getQuantity());
trace ("Author First Name: " + inventoryItem_3.getAuthor().getAuthorNameFirst());
trace ("Author Last Name: " + inventoryItem_3.getAuthor().getAuthorNameLast());
trace ("Author Birth Date: " + inventoryItem_3.getAuthor().getAuthorBirthDate());
You will get
Title: Howl
Quantity: 225
Author First Name: Allen
Author Last Name: Ginsberg
Author Birth Date: 12/25/75
TADA!!!
-Franky A.
Wednesday, July 30, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment