10.11.2007

Live from the New Media session

Well, that "this isn't so hard" feeling from the first half of the New Media session has been replaced with a "What the Deuce?!" vibe. OK, there's no Stewie rage, but we're climbing deeper into the wormhole that is Action Script coding in Flash.

The latest revelation -- which took our minds a little while to process -- are creating functions to do calculations for you. Example: Our test projects have been calculations for how far away from retirement we are. Input a number, click a button, and the Interwebs tell you how many years you've got left to go.

We started by writing code that simply subtracted the number you input from 65 (retirement age). I'm 29, so I'll retire in 36 years (yeah, right).

So, let's say the retirement age is 70 when I think about retiring. I could build another string of code to subtract from 70. Or, I could build a function, which will do the math for any number I want -- 65 or 70. Now, I can input my age on a page, and click "Retire at 65" or "Retire at 70." Why's this fascinating right now?

This amount of code:
myage = userageinput.text;
myretirement = 65;
//Figure out how many years til retirement
yearsleft = myretirement-myage;
//Create retirement message
//CONDITIONAL
//check if yearsleft is 0
if (yearsleft == 0) {
retiremessage = "Congratulations! you are retired.";
} else if (yearsleft < 0){
retiremessage = "You have been retired for "+(-yearsleft)+" years";
} else {
retiremessage = "You will retire in "+yearsleft+" years";
}
retiredisplay.htmlText = retiremessage;


Can become this:
on (release) {
setdisplay(65);
}


You'll notice the "//" above. Scott suggests before attempting to write code, you go through the Action Script window and just write down in plain English what you know you need the coding to do. Then, go back and do the coding based on your notes. Tips from a pro!

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home