Flash/Flex:Current Naming Conventions

From virtualMV2015wiki
Jump to: navigation, search
 Home  Flash11 (CS5) | Debugging and Testing <
Icon Objective.png

Objective Current Naming Conventions

By the end of this page you will be able to:

  • Have a referral resource for current naming conventions for Flash 11

Naming

The naming standards are mostly consistent with those of ECMAScript and Flash Player 9.

Abbreviations

Abbreviations are best avoided. However, some have been standardised and are generally acceptable:

  • acc for accessibility, as in ButtonAccImpl
  • auto for automatic, as in autoLayout
  • eval for evaluate, as in EvalBindingResponder
  • impl for implementation, as in ButtonAccImpl
  • info for information, as in GridRowInfo
  • num for number of, as in numChildren
  • min for minimum, as in minWidth
  • max for maximum, as in maxHeight
  • nav for navigation, as in NavBar
  • regexp for regular expression, as in RegExpValidator
  • util for utility, as in StringUtil

Acronyms

Various acronyms are common in Flash/Flex, such as AIR, CSS, HLOC, IME, MX, MXML, RPC, RSL, SWF, UI, UID, URL, WSDL, and XML.

An acronym is always all-uppercase or all-lowercase. The only time that all-lowercase is used is when the acronym is used by itself as an identifier, or at the beginning of an identifier, and the identifier should start with a lowercase letter.

Examples of identifiers with acronyms are CSSStyleDeclaration, IUID, uid, IIME, and imeMode.

Word boundaries

When an identifier contains multiple words, we use two ways of indicating word boundaries: intercaps (as in LayoutManager or measuredWidth) and underscores (as in object_proxy).

Type-specifying names

If you want to incorporate the type into the name, make it the last “word”. Don't use the old ActionScript 1 convention of concatenating abbreviated type suffixes such as _mc to indicate type. For example, name a border Shape border, borderSkin, or borderShape, but not border_mc.

Often, the best name for an object is simply the same as its type, with different casing:

var button:Button = new Button();

File names

Start the names of include files for \[Style(...)] metadata with an uppercase letter, use intercaps for subsequent words, and make the last word “Styles”: BorderStyles.as, ModalTransparencyStyles.as.

Style names

Start them with a lowercase letter and use intercaps for subsequent words: color, fontSize.

Enumerated values for String properties

Start them with a lowercase letter and use intercaps for subsequent words: "auto", "filesOnly",

Constant names

Use all uppercase letters with underscores between words: OFF, DEFAULT_WIDTH.

Method names

Start them with a lowercase letter and use intercaps for subsequent words: measure(), updateDisplayList().

Method names should always be verbs.

Event handler names

Event handlers should be named by concatenating “Handler” to the type of the event: mouseDownHandler().

Argument names

Use event (not e, evt, or eventObj) for the argument of every event handler:

Type declarations

Write a type annotation for every constant, variable, function argument, and function return value, even if the annotation is simply :* to indicate “no type”.


Use the narrowest type that is appropriate. For example, a loop index should be a int, not a Number, and certainly not an Object or *.

Use int for integers, even if they can't be negative. Use uint only for RGB colors, bit masks, and other non-numeric values.

Resources

Coding Conventions - Adobe Open Source Wiki [1]


Icon References.png References

  1. Adobe (2010) Coding Conventions Best Practices, retrieved 24 October 2010, from http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions#CodingConventions-Abbreviations

 

Day, S. (2010). Flash/Flex:Current Naming Conventions. Retrieved January 19, 2018, from http://www.virtualmv.com/wiki/index.php?title=Flash/Flex%3ACurrent_Naming_Conventions