Search Tutorials
Here is all of the code used in this tutorial:
function Human (name,sex) {
this.name = name;
this.sex = sex;
this.fReferers();
this.head = {hairColour : 0x663399, bigNose : true};
this.body = {};
//introducing class methods
this.fCreateArms(false,true);
this.fCreateLegs(true,true);
}
Human.prototype.fCreateArms = function (leftArmWaving,rightArmWaving) {
this.arms = {};
//short cut
var sc = this.arms;
sc.armLeft = { bWaving:leftArmWaving }
sc.armRight = { bWaving:rightArmWaving }
}
Human.prototype.fReferers = function () {
if(this.sex == "male") {
this.referers = {n1 : "He", n2 : "His"};
}
else{
this.referers = {n1 : "She", n2 : "Her"};
}
}
function fWaveArms(obj,bWaving){
for(var i in obj.arms){
obj.arms[i].bWaving = bWaving;
}
}
function fTraceRightArmWaving(obj) {
var rightArmWaving = (obj.arms.armRight.bWaving) ? " is " : " isn't ";
trace(obj.name+ " is a "+obj.sex+". "+ obj.referers.n1 + rightArmWaving+"waving with " + obj.referers.n2.toLowerCase() + " right hand.")
}
function fInitArmy () {
var arrMales = ["Nick","Yan","Pete","Andrew","Stelios","Niklas"];
var arrFemales = ["Camy","Jessica","Anna","Nicole","Jane","Helen"];
var maxLoop = arrMales.length;
for(var i=0;i<maxLoop;i++){
this[arrMales[i]] = new Human (arrMales[i],"male");
this[arrFemales[i]] = new Human (arrFemales[i],"female");
}
fWhosWaving (arrMales);
fWhosWaving (arrFemales);
}
function fWhosWaving (arrTroop) {
var maxLoop = arrTroop.length;
for(var i=0;i<maxLoop;i++){
fTraceRightArmWaving(this[arrTroop[i]]);
}
}
fInitArmy ();
If you found this useful please let me know as I'll write another 'chapter' demonstrating how to use these principals when creating components in Flash MX. Email nick@edition.co.uk.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||
|