AS1 OOP: Object Scope
by senocular
Overriding
With the local scope of a function, you also start to deal
with overriding. Overriding represents the circumstance when
a value of one accessible scope has precedence over a
similarly named value within another accessible scope. With
function calls, you have two readily accessible scopes
obtained through direct reference of variable names, the
timeline scope and the local scope of the function. The
local scope has precedence over the scope of the timeline so
if a value in the local scope of a function shares the same
variable name of a value in the timeline, the local
variable’s value will be retrieved when that variable is
accessed. For example
- num = 1;
- traceNum = function(){
- trace(num); // traces 1
- var num = 5;
- trace(num); // traces 5
- };
- traceNum();
- trace(num); // traces 1
You will see more with overriding later on. It can play
an important role in OOP.