Flexコード仕様


                    、    、    。
       :1.   ;2.      3.      4.    5. ASDoc
1.   
  :      ,             ;                  ,  acc(accessiblility) , auto(automatic), impl(implementation), info(infomation), num(number), min(minimum), max(maximum), nav(navigation), regexp(regular expression), util(utility)  。        Flex    ;
      :            。                        ,                            。
    :            ,       ,          ,  LayoutManager, object_proxy;                        ,      。
       :                   ,        ,        border      :border, borderSkin, borderShape;              :Button   button。
   :      ,        ,  controls, listClasses;             ,     、  、   、    。                        ,  bingding, logging, messaging, printing;    FooBar     fooBarClasses;
    :     API  ,            API    ,  include           ;          Styles ,      ,      ,      Styles: BorderStyles.as, ModalTrasparencyStyles.as;             ,     :icon_align_left.png;
      :    、     :mx_internal, object_proxy
    :  “I”  、      :IList, IFocusManager, IUID
   :      、      :Button, FocusManager;Event  (FoobarEvent),Error  (FooBarError),   (FooBarBackground, FooBarBorder, FooBarIcon…),utility (FooBarUtil,  FooBarUtils,    ,    );
    :      、      :move, creationComplete
Style  :      ,      :color, fontSize;
       :auto, filesOnly;
    :      ,     :OFF, DEFAULT_WIDTH,          ,              : <public static const FOO_BAR: String = “fooBar”>;
     :      ,      : i, width, numChildren;
  i      ,n      ;  j      ,m      :
for (var i:int = 0; i < n; i++)
{
    for (var j:int = 0; j < m; j++)
    {
        …
    }
}
  p  loop     :
for (var p:String in o)
{
    …
}
     getter/setter      getter/setter,             getter/setter,                 “$”       ,             final,       getter/setter          :
mx_internal final function get $numChildren():int
{
    return super.numChildren;
}
      :getter/setter  foo         _foo(     );
    :      ,          ,      :measure(), updateDisplayList();         getter/setter,     getFooBar(), setFooBar();  ,  getFooBar()                       findFooBar(), calculateFooBar(), determineFooBar()  ,   getter;                 ,                ,                 “$”       ,             final,                   :
mx_internal final function $addChild(child:DisplayObject):DisplayObject
{
    return super.addChild(child);
}
       :     Handler:mouseDownHandler();                          ,                 ,        :textinput_focusInHandler() (textinput focusin   handler);
    :setter   value:public function set label(value:String):void;       event:protected function mouseDownHandler(event:Event):void;
     :                       ;
     :    ,          ;
    :    “object”,      ;“item”    ,      ;renderer           ;“type” AS3  ,    “kind”;
2.     
      AS3     ,                 ;
    :        -strict –show-actionscript-warnings(flex-config.xml  );
     API:         API        API,         MXML      ;
    :       、  、        ;        ,         int,   Number,   Object;             MouseEvent   Event;      undefined      “*”,         Object  ,null  undefined;       Array,     “/*   */”           :var a:Array /* of String */ = [];
function f(a:Array /* of Number */):Array /* of Object */
{
    …
}
   :
undefined      ;
int uint:          ,     0x  ,       ;
RGB              ;
   -1  “     ”;
Number:         ,                       ,  alphaFrom = 0.0; alphaTo = 1.0;            ;
         e,  1.0e12,     E;
String:         ,          :  what’up, “Big Boy”?   ”What’s up, \”Big Boy\”?”,    ’what\’s up “Big Boy”?’;
Array:  “[]”,    new Array(),  [1, 2, 3]   new Array(1, 2, 3);                 ,         3   ,   new Array(3),                  [undefined, undefined, undefined],    [3];
Object:  {},    new Object();  {}, {a: 1, b: 2, c: 3};
Function:        ,           ;      ,       ,                 :function(i:int):void { doIt(i – 1); doIt(i + 1); }
RegExp:                    ,  var pattern:RegExp = /\d+/g;    var pattern:RegExp = new RegExp(“\\d+”, “g”);
XML XMLList:         ,        。  var node:XML = <name first=”Jane” last=”Doe”/>;   var node:XML = new XML(“<name first=\”Jane\” last=\”Doe\”/>”); XML            ,       。
Class:                       ,
    (Yes:):
import mx.controls.Button;
…
var b:Button = new Button();
    (No:):
import mx.controls.Button;
…
var b:Button = new mx.controls.Button();
    :
import mx.controls.Button;
import my.controls.Button;
…
var b:Button = new mx.controls.Button();
     :        (+, -, *, /, &&, ||, <, <=, >, >=, ==, !=)           ;                   。
      :   Boolean   true false  ;    int,uint, Number, String   Boolean ,  if(n !=0 )    if (n),   if (s != null && s != “”)   if (s),               Boolean ,   if (child)    if (child != null),  if (!child)    if (child != null);           as   ,                       null       。  IUIComponent(child).document   (child as UIComponnet).document;
  :                : if (n == 3) // “if n is 3″(Yes), if (3 == n) // “if 3 is n”(No);
++   –  :                      ,                         ;
     :              if/else   ,    null       ;
return item ? item.label : null (Yes)
if (! Item)
return null;
return item.label; (No)
              ;
new:                 :var b:Button = new Button(); (yes) var b:Button = new Button;(No);
  :              。
include:  include        #include,     ,           ;             ;
import:      ,       “*”;
use namespace :    ,           “::”:
Yes:
import mx.core.mx_internal;
// Later, in some method…
mx_internal::doSomething(); 
No:
import mx.core.mx_internal;
use namespace mx_internal;
// Later, in some method…
doSomething();
if: if/else            ,   {}   ;
Yes:
if (flag)
doThing1();
――――――――――――――――――――――――――――――――――――
if (flag)
    doThing1();
else
doThing2():
―――――――――――――――――――――――――――――――――――――
No:
if (flag)
{
    doThing1();
}
―――――――――――――――――――――――――――――――――――――
if (flag)
{
    doThing1();
}
else
{
    doThing2();
}
              ,    {}   :
Yes:
if (flag)
{
    doThing1();
}
else
{
    doThing2();
    doThing3();
}
―――――――――――――――――――――――――――――――――――――――
No:
if (flag)
    doThing1();
else
{
    doThing2();
    doThing3();
}
        ,         ,        ,       。        ,              。
Yes:
if (!condition1)
    return false;
…
if (!condition2)
    return false;
…
if (!condition2)
    return false;
…
return true;
No:
if (condition1)
{
    …
    if (condition2)
    {
        …
        if (condition3)
        {
            …
            return true;
        }
    }
}
return false;
for:     {}   ,              。                    ,        。
Yes:
var n:int = a.length;
for (var i:int = 0; i < n; i++)
{
    …
}
No:
for (var i:int = 0; i < a.length; i++)
{
    …
}
             ,              。
Yes:
for (var i:int = 0; i < 3; i++)
No:
var i:int;
for (i = 0; i < 3; i++)
{
   …
}
while:     {}   ,              。
do:     {}   ,              。
Switch:   case    {}   , {}       return    break  。       ,    return。return     break。default   case    :
Yes:
switch (n)
{
    case 0:
    {
        foo();
        break;
    }
    case 1:
    {
        bar();
        return;
    }
    case 2:
    {
        baz();
        return;
    }
    default:
    {
        blech();
        break;
    }
}
No:
switch (n)
{
    case 0:
        foo();
        break;
    case 1:
    {
        bar();
    }
    break;
    case 2:
        baz();
        return;
        break;
    default:
        blech();
}
return:            。             。
  :         。
Yes:
var a:int = 1;
var b:int = 2;
No:
var a:int = 1, b:int = 2;
override:     。override protected method measure():void(Yes) protected override method measure():void(No);
    :                  internal,        ,          。    API  public protected         ,                   ,        API           API。
static:        。  public static const MOVE:String =  &quot;move&quot;
final:        。   enum    final       (  $   )   final。
  :          static,        ,              。
  :               ,           ,             。
    :        ,            。
Yes:
private function f(i:int, j:int):int
{
    var a:int = g(i – 1) + g(i + 1);
    var b:int = g(a – 1) + g(a + 1);
    var c:int  = g(b – 1) + g(b + 1);
    return (a * b * c) / (a + b + c);
}
No:
private function f(i:int, j:int):int
{
    var a:int;
    var b:int;
    var c:int;
    a = g(i – 1) + g(i + 1);
    b = g(a – 1) + g(a + 1);
    c = g(b – 1) + g(b + 1);
    return (a * b * c) / (a + b + c);
}
                   ,                   。
Yes:
var i:int;
for (i = 0; i &lt; n; i++)
{
    …
}
for (i = 0; i &lt; n; i++)
{
    …
}
No:
for (var i:int = 0; i &lt; n; i++)
{
    …
}
for (var i:int = 0; i &lt; n; i++)
{
    …
}
 :    Object   ,      extends Object;
    :      ,          ,            super()。                ,                          。
Yes:
public function MyClass(foo:int, bar:int)
{
    this.foo = foo;
    this.bar = bar;
}
No:
public function MyClass(fooVal:int, barVal:int)
{
    foo = fooVal;
    bar = barVal;
}
                     ,           。            ,                 。
  、    、   、    :  ;
3.     
   as             。2008         :
///////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
///////////////////////////////////////////////////////////////////////////////
  :   80   ;
package、import 、use namespace  :  ;
    :  “ ”        ,   :Events, Styles, Effects, Excluded API       。   “ ”         “ ”  ,  ,     40   ,      //       。                 ,                   。
//————————————–
//  Events
//————————————–
/
**
 *  ASDoc comment.
 */
[Event
/**
 *  ASDoc comment.
 */
[Event
//--------------------------------------
//  Styles
//--------------------------------------
/**
 *  ASDoc comment.
 */
[Style
/**
 *  ASDoc comment.
 */
[Style]
//————————————–
//  Effects
//————————————–
/**
 *  ASDoc comment.
 */
[Effect
/**
 *  ASDoc comment.
 */
[Effect]
//————————————–
//  Excluded APIs
//————————————–
[Exclude(name=&quot;horizontalAlign&quot;, kind=&quot;style&quot;)]
[Exclude(name=&quot;verticalAlign&quot;, kind=&quot;style&quot;)]
//————————————–
//  Other metadata
//————————————–
[DefaultBindingProperty(source=&quot;text&quot;, destination=&quot;text&quot;)]
[IconFile(&quot;Text.png&quot;)]
   :  ;
Version.as     :                core/Version.as,      static const VERSION:STRING   :
include “../core/Version.as”;
  ,    :  ;
   :AS3   Array Object     ,     static var     (   static const),                          。
   、   :  ;
   :     static   getter setter,        ,           , getter   setter  ;
    、  :  ;
    (override properties):        getter setter,    ,     ,getter setter  ;
  :    setter setter    ,    ,     ,getter setter  。
    :             。
  :     。
       :             。
     :       。
     :  ;
4.   :
      Flex             。
  :80  。  :            ;                ;        ;                 ;
  :4  ;              Tab,                            ,  NotPad  8    ;
    :
 “ ”   :
    //————————————————————————–
    //
    //  Overridden methods
    //
    //————————————————————————–
 4  80 ,   8   ;
 “ ”   :     ,      。  :
    //———————————-
    //  visible
    //———————————-
 4  70 ,  8   ;
            ;
    :  、  、           ;
/**
 *  @private
 *  Holds something.
 */
var a:Number;
/**
 *  @private
 */
var b:Number
   :Inspectable[a="1", b="2"](Yes), Inspectable[a=1 b=2](No)。
    :           ,a[0] (yes), a[ 0 ] (no);
  :          ,    、  、   ;
    :                 ,[ 1, 2, 3 ] (yes), [1, 2, 3], [1,2,3](no);
                ;
static var numberNames:Array /* of String */ =
[
"zero",
    "one",
    "two",
    "three",
    "four",
    "five",
    "six",
    "seven",
    "eight",
    "nine"
];
    :                    ,                   ;{ a: 1, b: 2, c: 3 }(yes) {a: 1, b: 2, c: 3}, {a:1, b:2, c:3}(no);      :{} ;                   :
private static var TextStyleMap:Object =
{
    color: true,
    fontFamily: true,
    fontSize: true,
    fontStyle: true,
    fontWeight: true,
    leading: true,
    marginLeft: true,
    marginRight: true,
    textAlign: true,
    textDecoration: true,
    textIndent: true
};
    :     、  ,                :
Yes:
var n:Number;
No:
var n : Number;
var n: Number;
Yes:
function f(n:Number):void
No:
function f(n : Number) : void
function f(n: Number): void
      :      、              ,                   ;
   :      ,      ;
    :        ,                  ,              ,        ,          。           ,              ,           :
public function foo(parameter1:Number, parameter2:String,
                parameter3:Boolean):void
public function foo(parameter1:Number,
                      parameter2:String,
                parameter3:Boolean):void
public function aVeryLongFunctionName(
    parameter1:Number, parameter2:String,
parameter3:Boolean):void
    :f(a, b) (yes)  f(a,b), f( a, b ) (no);
if   : if       ,                        。
yes:
if (a < b)
no:
if(a < b)
if( a < b )
if ( a < b )
for   : for        ,                        。
Yes:
for (var i:int = 0; i < n; i++)
No:
for(var i:int = 0; i < n; i++)
for( var i:int = 0; i < n; i++ )
for ( var i:int = 0; i < n; i++ )
  for       ,            :
for (var aLongLoopVariableName:int = aLongInitialExpression;
    aLongLoopVariableName < aLongUpperLimit;
aLongLoopVariableName++)
switch  : switch        ,                        。
Yes: switch (n)
No:
switch(n)
switch( n )
switch ( n )
5. ASDoc
get set    ,      get/set    ,         :
/**
 *  @private
 *  The backing variable for the property.
 */
private var _someProp:Foo;
/**
 *  Place all comments for the property with the getter which is defined first.
 *  Comments should cover both get and set behavior as appropriate.
 */
public function get someProp():Foo
{
  …
}
/**
 *  @private
 */
public function set someProp(value:Foo):void
{
  …
}
ASDoc                     ,                 。            ,           get    ,          。
Yes:
[Bindable("somePropChanged")]
/**
 *  Comments for someProp
 */
public function get someProp():Foo
No:
/**
 * Comments for someProp
 */
[Bindable("somePropChanged")]
public function get someProp():Foo
    CSDN  ,       :http://blog.csdn.net/arshoon/archive/2008/05/21/2467161.aspx