Category Archives: variables

Dynamic Timeline Vars

Actionscript:
  1. this.myVar = "I am a dynamic variable";
  2. trace(this.myVar);
  3.  
  4. // trace(myVar) // will cause an error

This code will add dynamic untyped variables to the timeline. Although this example is pretty useless, it scratches the surface of an interesting topic.... by default all flash timeline code gets compiled into a giant dynamic document class that uses the undocumented addFrameScript() function. This means that all import statements on the timeline, even ones not on frame one become part of this large document class.

Also posted in timeline | Tagged , , | 2 Comments

const

Actionscript:
  1. const HALF_PI:Number = Math.PI / 2;
  2. const RADS:Number = Math.PI / 180;
  3.  
  4. trace(HALF_PI);
  5. // convert degrees to radians
  6. trace(180 * RADS);

When I have constant values I often forget to go ahead and make use of the const keyword. I used to do this a good deal when AS3 first came out.... not sure why I stopped doing it. Anyway, hopefully this post will help remind me to use them...

A very common use for them is of course defining event types:

Actionscript:
  1. // inside a class
  2. public static const RENDER_COMPLETE:String = "renderComplete";

Posted in variables | Tagged , | Leave a comment