//Steve Rhoades //Sample Code //Art Institute of Seattle //HelloVariables package{ import flash.display.*; /** *Our first change from HelloWorld, we've got a new Class name. Make sure the file name matches! */ public class HelloVariables extends Sprite{ /** *Have to change this main function name too */ public function HelloVariables(){ //this is how you declare a variable //var name:Type (= initial value); //here are some examples: var x:int; var y:int = 0; var z:int = 100; //note that we can print those the same way we printed "Hello, World!" trace(x); //prints 0, the default value of an int trace(y); //also 0, because that's what we set it to above trace(z); //100 /** *Variables come in all sorts of different types. The type tells the Flash engine how much memory *to give to each variable, and how to interpret those 1s and 0s. We will eventually create our own *types by creating our own objects. Here are some examples that we'll see a bunch of */ //we saw int already, but here's one with a good name. ints are integers var currentBalance:int = -100; //looks like we're in debt! //uints are unsigned ints. They can only be zero or positive. This comment should remind me //to talk a little bit about how data is stored, if I haven't already. var score:uint = 40; //what if you need non-whole numbers? Use Numbers! var fractionalValue:Number = 3.14; var negativeFraction:Number = -9.2; //Booleans, named for mathematician George Boole, are either true or false var alive:Boolean = true; //strings are collections of character data. Words or phrases. Not always exclusively letters! var greeting:String = "Hello, World!" //our original program used a string literal! var licensePlate:String = "I H8 U"; //anything within the quote is fair game, even spaces //let's print all that stuff out now trace(currentBalance); trace(score); trace(fractionalValue); trace(negativeFraction); trace(alive); trace(greeting); trace(licensePlate); } } }