Friday, March 26, 2010

Using custom variables in common object oriented programming

In this article, I'm going to be discussing some very basic OOP techniques using variables. Variables are a basic necessity in most programs, whether it be web or application based. So what is a variable you ask? Well, in computer terms, it is a constant, which can be updated, changed, or well...changed. Since flash is my forte, I'm going to discuss both actionscript and php. Code will be denoted by red.

The basic declarations (naming your variable) are a bit different in as3 and php. In actionscript, we use the starting prefix var, where as in php we use $. Once you get the basics of OOP, you'll start to notice the synatx similarities, and how to work well with both.

Lets say we want to write a math program. A basic calculator maybe. Well, in order to "calculate" we'll need to assign a variable to the number we will be calculating.

In AS3, we would start with:

var CalculatorNumber

In PHP:
$CalculatorNumber

Notice, spaces are not allowed, except after the var in AS3. It's required there for the flash player's recognition. It's preferred to use camel case as well. Now that we have a number that we can use as a variable, we will assign it a number. Usually, we would data type it as well, but it is not required for this simple app. Ok, so we have our variable, now, I'm going to write a function to process the variable.
, according to what the user clicks.


1 comment:

  1. Hey, I really like your blog it's amazing thanks for sharing this information on Custom graphic design with us keep it up and good luck with your next update hope you are doing fine...

    ReplyDelete