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";

This entry was posted in variables and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*