Archive for the 'Flash!' Category

Scoping Problem in External SWFs
_root won’t work in scenarios when you’re dealing with external SWF files. If you do use loadMovie( ), MovieClip.loadMovie( ), or the MovieClipLoader class, _root will always point to _level0. If you choose to load by levels; loadMovieNum(“url”,depth) instead, _root will point to the current level that is active.
An example of [...]


class State
{
var population:Number;
function State( )
{
//constructor
}
function setPopulation( population:Number) {    this.population = population +  ( population * 0.5 );    }
function getPopulation( ):Number {    return population;    }
}
Because of the versatility of getters and setters, getting and setting property values directly is considered bad coding practice. Set up and use Getter andSetter methods instead.
Using Implict Get and Set Methods
class [...]


onEnterFrame = function( ) {
//….
if ( blah) delete onEnterFrame;
}
same applies to set/clearInterval ( );


A simple class example
class Cube
{
private var length:Number;
private var height:Number;
private var width:Number;
//constructor
function Cube ( length:Number, height:Number, width:Number )
{
this.length = length;
this.height = height;
this.width = width;
}
function getVolume( ) : Number
{
return length * ( height * width);
}
} //end class
//create a Cube object
var myCube = new Cube( 3,3,3);
Now, you can access or set properties using the dot syntax
myCube.length = [...]


Using the Color class
To use a color class, you must first create an instance using the constructor. It takes in 1 paramater: the movie clip it should modify.
var myCol:Color = new Color( shirt_mc );
myCol.setRGB(0x FF3300);     //Accepts in a hex value
E.g.     btn.onRelease = function ( )
{
var R:Number = random(256);   //generates values between 0 to 255
var G:Number [...]


Capabilities Class (Top level)
This class contains information about the user’s computer, such as screen resolution and whether it can play sounds.
E.g.  var horizontalScreen:Number = System.capabilities.screenResolutionX;
ContextMenu Class (Instances)
It is the menu seen in Flash player when you right-click. Used in conjunction with instances of the ContextMenuItems class to create customized menus.
E.g.    //creates an instance of myCustomMenu
var [...]


OK, while what I’ve written here might not be really the basics for Flash, I’ve decided to make my virgin post a personal one. It covers syntaxes and structures which I tend to look them up a lot.
The Conditional (tenary) Operator
var myMood:String = ( money > 1000000 ) ? “Happy” : “Sad”;
which is equivalent [...]