Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories Understanding Objects in ActionScript - revised
Author: Nick Kuh | Website: http://www.editioninteractive.co.uk |

 
Page 4
«prev 1 2 3 4

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.

«prev 1 2 3 4

» Level Intermediate

Added: : 2003-01-01
Rating: 7.15 Votes: 27
Hits: 3005
» Author
I am a Flash Developer with 3 years commercial experience programming database-driven games and applications. I am currently working on a contract job developing e-learning software for UK schools.
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers