You are on page 1of 4

Action Script 3.

0 Programming 1) Core concepts Tools for writing action script code : Notepad or Flash Builder IDE Classes : Classes are blueprints for constructing something like airplane. An airplane has wheels, brakes , wings ,seats and so on.. This parts are objects based on classes(blueprint). Class ahmed {

Defining class: class ahmed{ } Creating Objects WE create objects from class--new ahmed // Variables and values: Variables local,instance,dynamic and static Local confined within the physical domain.. Class ahmed { Public function ahmed(){ var degree = BIT; } }

Instance variable attached to a particular object. Created within class definition Package Human{ Internal class ahmed{ Var degree = BIT; Instance Methods: Define things an object can do Created using function definition within a class block. Class ahmed { Function job(){ } } Package :container for group of classes

Declaration : package ahmed{ }

2)Conditional and Loops A type of statement that executes only when a specified condition is met .2 different Conditions if and switch. Loops: causes a statement block to be executed for as long as its test expression remains true. 5 different types : while, do-while, for , for-in, and for-each-in.

3) Instance Methods Revisited. Instance methods define the things an object can do. 4) Static variables and static methods. Static variables variables associated with class itself rather an instance of that class. Class ahmed { Static var job = Operations; } Static Methods defines functionality to the entire class not just an instance of that class. Class ahmed { Static function work (warehouse=dubai) } Chapter 5

Functions : Carry out some task independently of any class or object; Code: function ahmed (warehouse1, warehouse2){ }

Chapter 6 Inheritance It makes a class looks and feel like other class in addition to adding its own features. Chapter 7

package zoo { import flash.utils.setInterval; import flash.utils.clearInterval; internal class VirtualPet { private static var maxNameLength = 20; private static var maxCalories = 2000; private static var caloriesPerSecond = 100; private var petName; private var currentCalories = VirtualPet.maxCalories/2; private var digestIntervalID; public function VirtualPet (name) { setName(name); digestIntervalID = setInterval(digest, 1000); } public function eat (numberOfCalories) { if (currentCalories == 0) { trace(getName( ) + " is dead. You can't feed it." ); return; } var newCurrentCalories = currentCalories + numberOfCalories; if (newCurrentCalories > VirtualPet.maxCalories) { currentCalories = VirtualPet.maxCalories; } else { currentCalories = newCurrentCalories; } trace(getName( ) + " ate some food. It now has " + currentCalories + " calories remaining."); } public function getHunger ( ) { return currentCalories / VirtualPet.maxCalories; } public function setName (newName) { // If the proposed new name has more than maxNameLength characters... if (newName.length > VirtualPet.maxNameLength) { // ...truncate it

newName = newName.substr(0, VirtualPet.maxNameLength); } else if (newName == "") { // ...otherwise, if the proposed new name is an empty string, // then terminate this method without changing petName return; } // Assign the new, validated name to petName petName = newName; } public function getName ( ) { return petName; } private function digest ( ) { // If digesting more calories would leave the pet's currentCalories at // 0 or less... if (currentCalories - VirtualPet.caloriesPerSecond <= 0) { // ...stop the interval from calling digest( ) clearInterval(digestIntervalID); // Then give the pet an empty stomach currentCalories = 0; // And report the pet's death trace(getName( ) + " has died."); } else { // ...otherwise, digest the stipulated number of calories currentCalories -= VirtualPet.caloriesPerSecond; // And report the pet's new status trace(getName( ) + " digested some food. It now has " + currentCalories + " calories remaining."); } } } }

You might also like