104
Application Development Tips and Tricks
Initializing applications
Initialization of an application is used to set the starting state. It should be the first function
call in the application. This function should be the only call for initialization made in your
program; all other calls should be event driven.
// frame 1
this.init();
function init()
{
if (this.inited != undefined)
return;
this.inited = true;
// Initialization code here
}
Using var for local variables
All local variables should use the keyword
var
. This prevents variables from being accessed
globally and, more importantly, prevents variables from being inadvertently overwritten.
Using
var
also lets you use strict typing for an object for type checking at compile time. For
more information on strict typing, search for “strict data typing” in Flash Help.
For example, the following code does not use the keyword
var
to declare the variable and
inadvertently overwrites another variable.
counter = 7;
function loopTest(){
trace(counter);
for(counter = 0; counter < 5; +){
trace(counter);
}
}
trace(counter);
loopTest();
trace(counter);
This code outputs the following:
7
7
0
1
2
3
4
5
Summary of Contents for FLASH MEDIA SERVER 2-DEVELOPING MEDIA
Page 1: ...Developing Media Applications ...
Page 6: ...6 ...
Page 10: ...10 About This Manual ...
Page 36: ...36 Flash Media Server Architecture ...
Page 80: ...80 Debugging and Monitoring Applications ...
Page 106: ...106 Application Development Tips and Tricks ...
Page 114: ...114 ...