the weird function position !

I come across a weird problem when I wanted to delete some event listners:


public class test extends MovieClip
 {
 var already_loaded:Boolean = false;
 public function test ( )
 {
 reload ();
 btn.addEventListener (MouseEvent.MOUSE_DOWN, reload);

function reload ()
 {
 if (already_loaded == true)
 {

trace ("a hasEventListener "+mc.hasEventListener(MouseEvent.MOUSE_DOWN));
 mc.removeEventListener (MouseEvent.MOUSE_DOWN, tracer);
 trace ("b hasEventListener "+mc.hasEventListener(MouseEvent.MOUSE_DOWN));
 }

mc.addEventListener (MouseEvent.MOUSE_DOWN, tracer);
 function tracer (event:MouseEvent):void
 {
 trace ("ignit.");
 }

}
 already_loaded = true;
 }
 }

this code doesn’t work, but when i change the position of the function tracer(), it works


<pre>public class test extends MovieClip
 {
 var already_loaded:Boolean = false;
 public function test ( )
 {
 reload ();
 btn.addEventListener (MouseEvent.MOUSE_DOWN, reload);

function reload ()
 {
 if (already_loaded == true)
 {

trace ("a hasEventListener "+mc.hasEventListener(MouseEvent.MOUSE_DOWN));
 mc.removeEventListener (MouseEvent.MOUSE_DOWN, tracer);
 trace ("b hasEventListener "+mc.hasEventListener(MouseEvent.MOUSE_DOWN));
 }

mc.addEventListener (MouseEvent.MOUSE_DOWN, tracer);
 }
 function tracer (event:MouseEvent):void
 {
 trace ("ignit.");
 }

already_loaded = true;
 }
 }</pre>

int vs Number vs uint

In computing, signedness is a property of variables representing numbers in computer programs. A numeric variable is signed if it can represent both positive and negative numbers, and unsigned if it can only represent positive numbers.

by senocular

The general concensus is, use int when you’re not dealing with division or multiplication by decimal values. Generally, they’re best used for values used with +/- such as increment variables in loops.

Number is used for everything else but color which (esp when dealing with Alpha) you should use uint - in fact thats about the only time you should use uint.

by vijayram
As you are aware, Number data-type can accepts decimal values and hence floating-point operator(multiplication and division) is quicker when data-typed to Number.
So to avoid this performance overhead of implicit conversion, its better to data-type your variable to “int” during addition and subraction and whilst division and multiplication is involved use “Number” data-type.