ActionScript: Difference between revisions

Content deleted Content added
Added more information under Coding style
Line 11:
== Coding style ==
 
SomeThe of thesefollowing techniques are not required, but contribute towards more efficient, or at least more easily understandable code.
 
=== Naming ===
 
'''Naming''' involves capitalisation of code elements. Function names and variables should begin with a lower-case letter; objects should be capitalized. The first letter of each subsequent word should also be capitalised in both cases.
Line 17 ⟶ 19:
*Variable or property: ''userName'', ''myHtml'', ''rawXml''
 
The Flash code editor features code completion only when variables are named according to a specific format. This involves appending the variable type to the end of the variable name.
 
{| align="center" padding="9" style="border: 1px solid #444444;"
|+''Supported suffixes for code completion.''
! Object type !! Suffix string !! Example
Line 39 ⟶ 41:
| Color || _color || myColor_color
|}
 
=== Commenting code ===
 
'''Commenting code''' is always recommended. Comments should document the decisions made while building the code, telling the story of what it attempts to do. A future developer should be able to pickup the logic of the code with the assistance of the comments.
 
var clicks = 0; // This is a simple comment
 
/*
This is a multiline comment.
.....
.....
*/
 
Some common methods for indicating important comments are:
 
// :TODO: more work to be done here
// :BUG: [bugid] this is a known issue
// :KLUDGE: this bit isn't very elegant
// :TRICKY: lots of interactions, think twice before modifying
 
=== Timeline layout ===
 
* Don't use default layer names (Layer 1, Layer 2, etc.), provide your own intuitive labels.
* Groups layers together in folders, where it makes sense.
* Place ActionScript layers at the top of the stack, to easily locate all the code on the timeline.
* Lock layers currently not in use.
 
=== Scoping variables ===
 
_parent.myVar.blah = 100; // Use relative addressing like this
_root.myClip = 200; // Avoid absolute addressing as much as possible
_global.myVar = 300; // _global variables are available to all movies within the player
 
=== Keep actions together ===
 
* Whenever possible, all code should be placed in one ___location, making it easier to find and debug. Preferably frame 1 of the timeline. (However if a preloader is used, code may need to be placed on frame 2)
* Where large blocks of code are present, split the code into logical sections with comments as headers.
 
=== Avoid attaching code to Movie Clips or buttons ===
 
Attempt to write event code on a frame rather than on the object itself, unless it is purely a function call.
 
// CODE ON BUTTON - Not Recommended
on (release) {
play();
}
 
// CODE ON FRAME - Recommended
myButton.onRelease = function() {
play();
}
 
=== Source ===
 
Information above is summarised from Macromedia's ActionScript Coding Standards. For a more complete explanation, please see the full document.
 
http://www.macromedia.com/devnet/mx/flash/whitepapers/actionscript_standards.pdf
 
== External links ==