Skip to main content
Known Participant
April 14, 2011
Question

What cost var wher it can use

  • April 14, 2011
  • 1 reply
  • 490 views

What cost variable  wher it can use?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 14, 2011

what?

kiranemc2Author
Known Participant
April 14, 2011

what is public static const?

Kenneth Kawamoto
Community Expert
Community Expert
April 14, 2011

Public is something can be accessed from outside of the package, static is something belongs to the Class rather than instances of the Class, and const is a variable that defined once and does not change ("constant").

public static const, is therefore used to define a variable does not change and accessible from everywhere.

Where to use? For example, consider this scenario: You have this const defining the highlight colour as red in a class "Main":

public static const HIGHLIGHTCOLOUR:uint = 0xff0000;

You can access this variable from anywhere using:

Main.HIGHLIGHTCOLOUR

You'd use public static const for this because the same highlight colour is applied to the entire project throughout.

Then you changed your mind and decided the highlight colour should be pink instead, but the colour is used for 100s of objects already. Imagine going through every single objects one by one to change the colour to pink... Instead, you just edit the const:

public static const HIGHLIGHTCOLOUR:uint = 0xffc0cb;

That's it. Beauty of object orientated AS3