> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codeant.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Flex

<AccordionGroup>
  <Accordion title="public static fields should be constant">
    <div class="paragraph">
      <p>There is no good reason to declare a field "public" and "static" without also declaring it "const". Most of the time this is a kludge to share a state among several objects. But with this approach, any object can do whatever it wants with the shared state, such as setting it to <code>null</code>.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public class Greeter {
      public static var foo:Foo = new Foo(...);
      ...
      }
      ```

      ```flex Fix theme={null}
      public class Greeter {
      public static const FOO:Foo = new Foo(...);
      ...
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Classes that extend Event should override Event.clone()">
    <div class="paragraph">
      <p>Overriding Event.clone() is a required part of the API contract:</p>
    </div>

    <div class="quoteblock">
      <blockquote>
        <div class="paragraph">
          <p>You are required to override the Event.clone() method in your Event subclass. The clone() method returns a cloned copy of the event object by setting the type property and any new properties in the clone. Typically, you define the clone() method to return an event instance created with the new operator.</p>
        </div>
      </blockquote>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public class MyEvent extends Event {...}
      ```

      ```flex Fix theme={null}
      public class MyEvent extends Event 
      {
      ...
      override public function clone():Event {
      return new MyEvent(...);
      }
      ...
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Alert.show(...) should not be used">
    <div class="paragraph">
      <p><code>Alert.show(...)</code> can be useful for debugging during development, but in production mode this kind of pop-up could expose sensitive information to attackers, and should never be displayed.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      if (unexpectedCondition)
      {
      Alert.show("Unexpected Condition");
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="The element type of an array field should be specified">
    <div class="paragraph">
      <p>Quoted from the Flex documentation :</p>
    </div>

    <div class="quoteblock">
      <blockquote>
        <div class="paragraph">
          <p>When you define an Array variable in ActionScript, you specify Array as the data type of the variable. However, you cannot specify the data type of the elements of the Array.</p>
        </div>

        <div class="paragraph">
          <p>To allow the Flex MXML compiler to perform type checking on Array elements, you can use the \[ArrayElementType] metadata tag to specify the allowed data type of the Array elements.</p>
        </div>
      </blockquote>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public var newStringProperty:Array;
      public var newNumberProperty:Array;
      ```

      ```flex Fix theme={null}
      [ArrayElementType("String")] 
      public var newStringProperty:Array;

      [ArrayElementType("Number")] 
      public var newNumberProperty:Array;
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Only while, do and for statements should be labelled">
    <div class="paragraph">
      <p>Any statement or block of statements can be identified by a label, but those labels should be used only on <code>while, do-while and for</code> statements. Using labels in any other context leads to unstructured, confusing code.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      myLabel:if (i % 2 == 0) {  // Noncompliant
      if (i == 12) {
      print("12");
      break myLabel;
      }
      print("Odd number, but not 12");
      }
      ```

      ```flex Fix theme={null}
      myLabel:for (i = 0; i < 10; i++) {   // Compliant
      print("Loop");
      break myLabel;
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Statements should end with semicolons">
    <div class="paragraph">
      <p>In Flex, the semicolon is optional as a statement separator, but omitting semicolons can be confusing.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      function fun() {
      return   // Noncompliant
         5   // Noncompliant
      }
      print(fun());  // prints "undefined", not "5"
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="The flash.system.Security.exactSettings property should never be set to false">
    <div class="paragraph">
      <p>The Security.exactSettings value should remain set at the default value of true. Setting this value to false could make the SWF vulnerable to cross-domain attacks.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      Security.exactSettings = false;
      ```

      ```flex Fix theme={null}
      Security.exactSettings = true;
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="The special star type should not be used">
    <div class="paragraph">
      <p>According to the ActionScript language reference, the star type:</p>
    </div>

    <div class="quoteblock">
      <blockquote>
        <div class="paragraph">
          <p>Specifies that a property is untyped. Use of the asterisk symbol for a type annotation is equivalent to using no type annotation. Expressions that read from untyped properties are considered untyped expressions. Use of untyped expressions or properties is recommended in the following circumstances:</p>
        </div>

        <div class="ulist">
          <ul>
            <li>
              <p>When you want to defer type checking to runtime. You can use an untyped property or expression to circumvent compile-time type checking in strict mode. Note, however, that runtime type checking of assignment statements occurs whether you use strict mode or not.</p>
            </li>

            <li>
              <p>When you want to store the value undefined in a property. Unlike previous versions of ActionScript, the value undefined is not a member of the Object data type. You must use an untyped property to store the value undefined.</p>
            </li>
          </ul>
        </div>
      </blockquote>
    </div>

    <div class="paragraph">
      <p>But deferring type checking to runtime can highly impact the robustness of the application because the compiler is unable to assist the developer.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      var obj:*;  // Noncompliant
      var foo:* = new Something();  // Noncompliant
      ```

      ```flex Fix theme={null}
      var obj:Something;
      var foo:Something = new Something();
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Function call arguments should not start on new lines">
    <div class="paragraph">
      <p>Because semicolons at the ends of statements are optional, starting function call arguments on a separate line makes the code confusing. It could lead to errors and most likely <em>will</em> lead to questions for maintainers.</p>
    </div>

    <div class="paragraph">
      <p>What was the initial intent of the developer?</p>
    </div>

    <div class="olist arabic">
      <ol class="arabic">
        <li>
          <p>Define a function and then execute some unrelated code inside a closure ?</p>
        </li>

        <li>
          <p>Pass the second function as a parameter to the first one ?</p>
        </li>
      </ol>
    </div>

    <div class="paragraph">
      <p>The first option will be the one chosen by the JavaScript interpreter.</p>
    </div>

    <div class="paragraph">
      <p>By extension, and to improve readability, any kind of function call argument should not start on new line.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      var fn = function () {
      //...
      }

      (function () { // Noncompliant
      //...
      })();
      ```

      ```flex Fix theme={null}
      // define a function
      var fn = function () {
      //...
      }; // <-- semicolon added

      // then execute some code inside a closure
      (function () {
      //...
      })();
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Event names should not be hardcoded in event listeners">
    <div class="paragraph">
      <p>Using plain string event names in even listeners is an anti-pattern; if the event is renamed, the application can start behaving unexpectedly. A constant variable should be used instead.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      import flash.display.Sprite; 
      import flash.events.MouseEvent; 

      class ChildSprite extends Sprite 
      { 
      public function ChildSprite() 
      { 
          ...
          addEventListener("CustomEvent", clickHandler);   // Noncompliant
      } 
      } 

      function clickHandler(event:CustomEvent):void 
      { 
      trace("clickHandler detected an event of type: " + event.type); 
      trace("the this keyword refers to: " + this); 
      }
      ```

      ```flex Fix theme={null}
      import flash.display.Sprite; 
      import flash.events.MouseEvent; 

      class ChildSprite extends Sprite 
      { 
      public const CUSTOM_EVENT:String = "CustomEvent";

      public function ChildSprite() 
      { 
          ...
          addEventListener(CUSTOM_EVENT, clickHandler); 
      } 
      } 

      function clickHandler(event:CustomEvent):void 
      { 
      trace("clickHandler detected an event of type: " + event.type); 
      trace("the this keyword refers to: " + this); 
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Method visibility should be explicitly declared">
    <div class="paragraph">
      <p>Access modifiers define which classes can access properties, variables, methods, and other classes. If an access modifier is not specified, the access level defaults to \`internal, which grants access to all classes in the same package. This may be what is intended, but it should be specified explicitly to avoid confusion.</p>
    </div>

    <div class="paragraph">
      <p>Available access modifiers are:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>internal - access allowed within the same package</p>
        </li>

        <li>
          <p>private - access allowed only within the same class</p>
        </li>

        <li>
          <p>protected - access allowed to the class and its child classes</p>
        </li>

        <li>
          <p>public\` - unfettered access by all</p>
        </li>
      </ul>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      function checkResources():Boolean { 
      ...
      return true;
      }
      ```

      ```flex Fix theme={null}
      public function checkResources():Boolean { 
      ...
      return true;
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="ManagedEvents tags should have companion Event tags">
    <div class="paragraph">
      <p>The "ManagedEvents" metadata tag allows you to flag an event as being managed. By definition this "ManagedEvents" metadata tag should be used in pair with an "Event" metadata tag.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      [Event(name="message", type="my.package.MyEvemt")]
      [ManagedEvents("mes")]       //This "mes" event is not defined with the "Event" metadata tag
      public class MyClass {...}
      ```

      ```flex Fix theme={null}
      [Event(name="message", type="my.package.MyEvemt")]
      [ManagedEvents("message")]
      public class MyClass {...}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="with statements should not be used">
    <div class="paragraph">
      <p>Never use <code>with</code> statements, since they decrease readability. When you do not specify a variable’s scope, you do not always know where you are setting properties, so your code can be confusing.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      with (foo) { // Noncompliant
      return x;  // is it a property of foo or local variable ?
      }
      ```

      ```flex Fix theme={null}
      return foo.x;
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Objects should not be instantiated inside a loop">
    <div class="paragraph">
      <p>It can be expensive to instantiate a new object, and doing so inside a loop is typically an error. Instead, create the object once, before the loop.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      for (var i:int = 0; i < 10; i++) {
      var temp:MyObj = new MyObject();  // Noncompliant
      //...  
      }
      ```

      ```flex Fix theme={null}
      var temp:MyObj = new MyObject();
      for (var i:int = 0; i < 10; i++) {
      //...  
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="The trace function should not be used">
    <div class="paragraph">
      <p>The <code>trace() function outputs debug statements, which can be read by anyone with a debug version of the Flash player. Because sensitive information could easily be exposed in this manner, trace()</code> should never appear in production code.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      var val:Number = doCalculation();
      trace("Calculation result: " + val);  // Noncompliant
      ```

      ```flex Fix theme={null}
      var val:Number = doCalculation();
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Package definition should be separate from Class definition">
    <div class="paragraph">
      <p>Declaring the package and class together has been deprecated since ActionScript 3. The package definition should be declared outside of the class definition even if the old syntax is still supported.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      class P.A {...}
      ```

      ```flex Fix theme={null}
      package P {    
      class A {...}
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Loggers should be private static const and should share naming convention">
    <div class="paragraph">
      <p>Loggers should be:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>\`private: not accessible outside of their parent classes. If another class needs to log something, it should instantiate its own logger.</p>
        </li>

        <li>
          <p>static: not dependent on an instance of a class (an object). When logging something, contextual information can of course be provided in the messages but the logger should be created at class level to prevent creating a logger along with each object.</p>
        </li>

        <li>
          <p>const\`: created once and only once per class.</p>
        </li>
      </ul>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public const logger:ILogger = LogUtil.getLogger(MyClass);
      ```

      ```flex Fix theme={null}
      private static const LOG:ILogger = LogUtil.getLogger(MyClass);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Function names should comply with a naming convention">
    <div class="paragraph">
      <p>For example, with the default provided regular expression <code>^\[a-z]\[a-zA-Z0-9]\*\$</code>, the function:</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      function DoSomething(){...} /* Noncompliant */
      ```

      ```flex Fix theme={null}
      function doSomething(){...}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Multiple ++ or -- unary operators should not be used in a single arithmetic expression">
    <div class="paragraph">
      <p>Using several "--" or "++" unary operators in the same arithmetic expression can quickly make the expression unreadable.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      var j:int = foo++ - --bar;
      ```

      ```flex Fix theme={null}
      bar--;
      var j:int = foo++ - bar;
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Control flow statements if, for, while and switch should not be nested too deeply">
    <div class="paragraph">
      <p>Nested control flow statements <code>if, for, while, do while and switch</code>  are often key ingredients in creating
      what’s known as "Spaghetti code". This code smell can make your program difficult to understand and maintain.</p>
    </div>

    <div class="paragraph">
      <p>When numerous control structures are placed inside one another, the code becomes a tangled, complex web.
      This significantly reduces the code’s readability and maintainability, and it also complicates the testing process.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      if (condition1) {                  // Compliant - depth = 1
      /* ... */
      if (condition2) {                // Compliant - depth = 2
        /* ... */
        for(int i = 0; i < 10; i++) {  // Compliant - depth = 3, not exceeding the limit
          /* ... */
          if (condition4) {            // Noncompliant - depth = 4
            if (condition5) {          // Depth = 5, exceeding the limit, but issues are only reported on depth = 4
              /* ... */
            }
            return;
          }
        }
      }
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Overriding methods should do more than simply call the same method in the super class ">
    <div class="paragraph">
      <p>Overriding a method just to call the same method from the super class without performing any other actions is useless and misleading.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      override public function doSomething() : void
      { 
      super.doSomething(); 
      }

      override public function isLegal(action:Action) : Boolean 
      {      
      return super.isLegal(action);
      }
      ```

      ```flex Fix theme={null}
      override public function doSomething() : void
      { 
      super.doSomething();                             // Compliant - not simply forwarding the call
      doSomethingElse();
      }

      override public function isLegal(action:Action) : Boolean 
      {      
      return super.isLegal(new Action(...));   // Compliant - not simply forwarding the call
      }

      [Deprecated(replacement="isAuthorized")]
      override public function isLegal(action:Action) : Boolean 
      {      
      return super.isLegal(action);   // Compliant as there is a metadata
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Constructors should not dispatch events">
    <div class="paragraph">
      <p>A listener can be attached to an object only after it has been constructed. So dispatching an event in a constructor is useless and error prone.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public class MyClass 
      {
      public function MyClass()
      { 
      dispatchEvent( new Event( "uselessEvent" ) );
      }
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Constructor bodies should be as lightweight as possible">
    <div class="paragraph">
      <p>In ActionScript 3, constructor code is always interpreted rather than compiled by the JIT at runtime, which is why the body of a constructor should be as lightweight as possible. As soon as a constructor contains branches ("if", "for", "switch", …​) an issue is logged.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public class Foo
      {
      public function Foo()
      {
      if (condition) {  // Noncompliant
        // ...
      }
      }
      }
      ```

      ```flex Fix theme={null}
      public class Foo
      {
      public function Foo()
      {
      init()
      }

      private function init():void 
      {
      if (condition) { 
        // ...
      }
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Statements, operators and keywords specific to ActionScript 2 should not be used">
    <div class="paragraph">
      <p>Usage of statements, operators and keywords specific to ActionScript 2 does not allow to migrate to ActionScript 3. This includes "intrinsic" keyword, set variable statement and following list of operators:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>\`\<> (inequality) - use != instead</p>
        </li>

        <li>
          <p>add (concatenation (strings)) - use + instead</p>
        </li>

        <li>
          <p>eq (equality (strings)) - use == instead</p>
        </li>

        <li>
          <p>ne (not equal (strings)) - use != instead</p>
        </li>

        <li>
          <p>lt (less than (strings)) - use \< instead</p>
        </li>

        <li>
          <p>le (less than or equal to (strings)) - use \<= instead</p>
        </li>

        <li>
          <p>gt (greater than (strings)) - use > instead</p>
        </li>

        <li>
          <p>ge (greater than or equal to (strings)) - use >= instead</p>
        </li>

        <li>
          <p>and (logical and) - use && instead</p>
        </li>

        <li>
          <p>or (logical or) - use || instead</p>
        </li>

        <li>
          <p>not (logical not) - use !\` instead</p>
        </li>
      </ul>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      if (true != false) { // Compliant
      }

      if (true <> false) { // Noncompliant
      }

      set("varName", value); // Noncompliant
      varName = value; // Compliant
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Cases in a switch should not have the same condition">
    <div class="paragraph">
      <p>Having multiple cases in a <code>switch</code> with the same condition is confusing at best. At worst, it’s a bug that is likely to induce further bugs as the code is maintained.</p>
    </div>

    <div class="paragraph">
      <p>If the first case ends with a break, the second case will never be executed, rendering it dead code. Worse there is the risk in this situation that future maintenance will be done on the dead case, rather than on the one that’s actually used.</p>
    </div>

    <div class="paragraph">
      <p>On the other hand, if the first case does not end with a break, both cases will be executed, but future maintainers may not notice that.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      switch(i) {
      case 1:
      //...
      break;
      case 5:
      //...
      break;
      case 3:
      //...
      break;
      case 1:  // Noncompliant
      //...
      break;
      }
      ```

      ```flex Fix theme={null}
      switch(i) {
      case 1:
      //...
      break;
      case 5:
      //...
      break;
      case 3:
      //...
      break;
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Variables of the Object type should not be used">
    <div class="paragraph">
      <p>Creating a new variable with the type "Object" means that it may be used to store any kind of object. This feature may be required in some specific contexts, but it leaves the compiler unable to do any kind of type checking, and is therefore a hazardous practice.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      var obj:Object = new String(); // Noncompliant; Object used explicitly
      var foo = new Object(); // Noncompliant; Object used explicitly
      var bar = {name:String, age:int};  // Noncompliant; Object implicitly created
      ```

      ```flex Fix theme={null}
      var obj:String = new String();
      var foo:IPortfolio = new Portfolio();
      class Person {
      public var name:String;
      public var age:int;
      }
      var bar:Person = new Person();
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="LocalConnection should be configured to narrowly specify the domains with which local connections to other Flex application are allowed">
    <div class="paragraph">
      <p>A <code>LocalConnection object is used to invoke a method in another LocalConnection</code> object, either within a single SWF file or between multiple SWF files. This kind of local connection should be authorized only when the origin (domain) of the other Flex applications is perfectly defined.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      localConnection.allowDomain("*");
      ```

      ```flex Fix theme={null}
      localConnection.allowDomain("www.myDomain.com");
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Event types should be defined in metadata tags">
    <div class="paragraph">
      <p>According to the Flex documentation :</p>
    </div>

    <div class="quoteblock">
      <blockquote>
        <div class="paragraph">
          <p>In an ActionScript file, when you define component events or other aspects of a component that affect more than a single property, you add the metadata tag outside the class definition so that the metadata is bound to the entire class, as the following example shows:</p>
        </div>

        <div class="listingblock">
          <div class="content">
            \`// Add the \[Event] metadata tag outside of the class file.
            \[Event(name="enableChange", type="flash.events.Event")]
            public class ModalText extends TextArea \{

            ...

            // Define class properties/methods
            private var \_enableTA:Boolean;

            // Add the \[Inspectable] metadata tag before the individual property.
            \[Inspectable(defaultValue="false")]
            public function set enableTA(val:Boolean):void \{
            \_enableTA = val;
            this.enabled = val;

            // Define event object, initialize it, then dispatch it.
            var eventObj:Event = new Event("enableChange");
            dispatchEvent(eventObj);
            }
            }\`
          </div>
        </div>
      </blockquote>
    </div>

    <div class="paragraph">
      <p>In this example, the "enableChange" event must be considered part of the API. Therefore, it should be strongly typed.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      [Event(name="enableChange")] 
      public class ModalText extends TextArea {...}
      ```

      ```flex Fix theme={null}
      [Event(name="enableChange", type="flash.events.Event")] 
      public class ModalText extends TextArea {...}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Constructors should not have a void return type">
    <div class="paragraph">
      <p>Even though this is syntactically correct, the <code>void</code> return type should not be used in the signature of a constructor. Indeed some developers might be confused by this syntax, believing that the constructor is in fact a standard function.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public class Foo   
      {
      public function Foo() : void
      {...}      
      }
      ```

      ```flex Fix theme={null}
      public class Foo   
      {
      public function Foo()
      {...}      
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="MovieClip.onEnterFrame event handler should not be used">
    <div class="paragraph">
      <p>The <code>onEnterFrame event handler is continually invoked at the frame rate of the SWF file, regardless of which individual movie frame it is set for. Having too many onEnterFrame</code> handlers can seriously degrade performance.</p>
    </div>

    <div class="paragraph">
      <p>If the use of this event handler cannot be avoided entirely, then it should be created as close to its use as possible, and then destroyed as soon as possible afterward.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      movieClip.onEnterFrame = function () {   // Noncompliant
      // ...
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Public constants and fields initialized at declaration should be const static rather than merely const">
    <div class="paragraph">
      <p>Making a public constant just <code>const as opposed to static const</code> leads to duplicating its value for every instance of the class, uselessly increasing the amount of memory required to execute the application.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      public class Myclass 
      {
      public const THRESHOLD:int = 3;   
      }
      ```

      ```flex Fix theme={null}
      public class Myclass 
      {
      public static const THRESHOLD:int = 3;   
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Dynamic classes should not be used">
    <div class="paragraph">
      <p>A dynamic class defines an object that can be altered at run time by adding or changing properties and methods. This extremely powerful mechanism should be used very carefully, and only in very limited use cases.</p>
    </div>

    <div class="paragraph">
      <p>Indeed, by definition dynamic classes make refactoring difficult and prevent the compiler from raising potential errors at compile time.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      dynamic public class DynamicFoo
      {...}
      ```

      ```flex Fix theme={null}
      public class Foo  //Note that the class has been renamed to avoid confusion 
      {...}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Security.allowDomain(...) should only be used in a tightly focused manner">
    <div class="paragraph">
      <p>Calling Security.allowDomain("\*") lets any domain cross-script into the domain of this SWF and exercise its functionality.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```flex Bad theme={null}
      Security.allowDomain("*");
      ```

      ```flex Fix theme={null}
      Security.allowDomain("www.myDomain.com");
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="A function should have a single point of exit at the end of the function">
    <div class="paragraph">
      <p>This is required by IEC 61508, under good programming style.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      function func1() { // Noncompliant - there are two points of exit
      if (false) {
      return;
      }
      }

      function func2() { // Noncompliant - there are two points of exit
      if (a > 0) {
      return 0;
      }
      return -1;
      }
      ```

      ```flex Fix theme={null}
      function func1() {
      return;
      }

      function func2() {
      }

      function func3();
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Octal values should not be used">
    <div class="paragraph">
      <p>Integer literals starting with a zero are octal rather than decimal values. While using octal values is fully supported, most developers do not have experience with them. They may not recognize octal values as such, mistaking them instead for decimal values.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      var myNumber:int = 010;  // Noncompliant. myNumber will hold 8, not 10 - was this really expected?
      ```

      ```flex Fix theme={null}
      var myNumber:int = 8;
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Mergeable if statements should be combined">
    <div class="paragraph">
      <p>Nested code - blocks of code inside blocks of code - is eventually necessary, but increases complexity. This is why keeping the code as flat as possible, by avoiding unnecessary nesting, is considered a good practice.</p>
    </div>

    <div class="paragraph">
      <p>Merging if statements when possible will decrease the nesting of the code and improve its readability.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      if (condition1) {
      if (condition2) {             // Noncompliant
      ...
      }
      }
      ```

      ```flex Fix theme={null}
      if (condition1 && condition2) {
      ...
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Methods should not be empty">
    <div class="paragraph">
      <p>An empty \{operationName} is generally considered bad practice and can lead to confusion, readability, and maintenance issues.
      Empty \{operationName}s bring no functionality and are misleading to others as they might think the \{operationName} implementation fulfills a specific and identified requirement.</p>
    </div>

    <div class="paragraph">
      <p>There are several reasons for a \{operationName} not to have a body:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.</p>
        </li>

        <li>
          <p>It is not yet, or never will be, supported. In this case an exception should be thrown.</p>
        </li>

        <li>
          <p>The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.</p>
        </li>
      </ul>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public function shouldNotBeEmpty():void {  // Noncompliant - method is empty
      }

      public function notImplemented():void {  // Noncompliant - method is empty
      }

      public override function emptyOnPurpose():void {  // Noncompliant - method is empty
      }
      ```

      ```flex Fix theme={null}
      public function shouldNotBeEmpty():void {
      doSomething();
      }

      public function notImplemented():void {
      throw new Error("notImplemented() cannot be performed because ...");
      }

      public override function emptyOnPurpose():void {
      // comment explaining why the method is empty
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unused private fields should be removed">
    <div class="paragraph">
      <p>If a private field is declared but not used locally, its limited visibility makes it dead code.</p>
    </div>

    <div class="paragraph">
      <p>This is either a sign that some logic is missing or that the code should be cleaned.</p>
    </div>

    <div class="paragraph">
      <p>Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand and preventing bugs from being introduced.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public class MyClass {
      private var foo:int = 4;  // Noncompliant: foo is unused and should be removed

      public function compute(a:int):int{
      return a * 4;
      }
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unused function parameters should be removed">
    <div class="paragraph">
      <p>A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body.
      While this might seem harmless at first glance, it can lead to confusion and potential errors in your code.
      Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore.
      Therefore, removing function parameters that are not being utilized is considered best practice.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      override function doSomething(a:int):void {    // ignored
      compute(a);
      }

      ...

      class AbstractSomething {
      public function doSomething(a:int) {  // ignored
      throw new IllegalOperationError("doSomething() is abstract");
      }

      ...

      interface I {
      function action(a:int, b:int);
      }

      class C extends I {
      function action(a:int, b:int) { // ignored
      return doSomethignWith(a);
      }
      }

      function clickHandler(event:MouseEvent):void { // ignored
      trace("click");
      }
      ```

      ```flex Fix theme={null}
      function doSomething(a:int, b:int):void      // "b" is unused
      {
      compute(a);
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Package names should comply with a naming convention">
    <div class="paragraph">
      <p>Shared naming conventions improve readability and allow teams to collaborate efficiently.
      This rule checks that all package names match a provided regular expression.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      package org.Example {  // Noncompliant
      ...
      }
      ```

      ```flex Fix theme={null}
      package org.example { 
      ...
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Class names should comply with a naming convention">
    <div class="paragraph">
      <p>Shared naming conventions allow teams to collaborate efficiently.</p>
    </div>

    <div class="paragraph">
      <p>This rule raises an issue when a class name does not match a provided regular expression.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public class myClass {...} /* Noncompliant */
      ```

      ```flex Fix theme={null}
      public class MyClass {...}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="for loop stop conditions should be invariant">
    <div class="paragraph">
      <p>A \`for loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.</p>
    </div>

    <div class="paragraph">
      <p>Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.</p>
    </div>

    <div class="paragraph">
      <p>This rule tracks three types of non-invariant stop conditions:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>When the loop counters are updated in the body of the for\` loop</p>
        </li>

        <li>
          <p>When the stop condition depend upon a method call</p>
        </li>

        <li>
          <p>When the stop condition depends on an object property, since such properties could change during the execution of the loop.</p>
        </li>
      </ul>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      for (var i = 0; i < 10; i++) {
      ...
      i = i - 1; // Noncompliant 
      ...
      } 

      for (var i = 0; i < getMaximumNumber(); i++) {...}
      ```

      ```flex Fix theme={null}
      int stopCondition = getMaximumNumber();
      for (var i = 0; i < stopCondition; i++) {...}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Functions should not contain too many return statements">
    <div class="paragraph">
      <p>Having too many return statements in a function increases the function’s essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      function myFunction():boolean { // Noncompliant as there are 4 return statements
      if (condition1) {
      return true;
      } else {
      if (condition2) {
        return false;
      } else {
        return true;
      }
      }
      return false;
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="switch case clauses should not have too many lines of code">
    <div class="paragraph">
      <p>The <code>switch statement should be used only to clearly define some new branches in the control flow. As soon as a case clause contains too many statements this highly decreases the readability of the overall control flow statement. In such case, the content of the case</code> clause should be extracted into a dedicated method.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      switch (myVariable) {
      case 0:       // Noncompliant - 6 lines till next case or default case
      trace("");
      trace("");
      trace("");
      trace("");
      break;
      case 1:
      ...
      }
      ```

      ```flex Fix theme={null}
      switch (myVariable) {
      case 0:
      printSomething()
      break;
      case 1:
      ...
      }
      ...
      private function printSomething() {
      trace("");
      trace("");
      trace("");
      trace("");
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Track uses of TODO tags">
    <div class="paragraph">
      <p>Developers often use TODO tags to mark areas in the code where additional work or improvements are needed but are not implemented immediately.
      However, these TODO tags sometimes get overlooked or forgotten, leading to incomplete or unfinished code.
      This rule aims to identify and address unattended TODO tags to ensure a clean and maintainable codebase.
      This description explores why this is a problem and how it can be fixed to improve the overall code quality.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      void doSomething() {
      // TODO
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Field names should comply with a naming convention">
    <div class="paragraph">
      <p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.</p>
    </div>

    <div class="paragraph">
      <p>The goal of a naming convention is to make the code more readable and understandable, which makes it easier to maintain and debug.
      It also ensures consistency in the code, especially when multiple developers are working on the same project.</p>
    </div>

    <div class="paragraph">
      <p>This rule checks that field names match a provided regular expression.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      class MyClass {
      public var my_field:int;
      }
      ```

      ```flex Fix theme={null}
      public class MyClass {
      public var myField:int;
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unused private functions should be removed">
    <div class="paragraph">
      <p>This rule raises an issue when a \{visibility} \{operationName} is never referenced in the code.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public class Foo
      {
      public static function doSomething(): void  // Compliant - public function
      {
      var foo:Foo = new Foo();
      ...
      }

      private function unusedPrivateFunction(): void {...}  // Noncompliant
      }
      ```

      ```flex Fix theme={null}
      public class Foo
      {
      public static function doSomething(): void  // Compliant - public function
      {
      var foo:Foo = new Foo();
      ...
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Useless if(true) {...} and if(false){...} blocks should be removed">
    <div class="paragraph">
      <p>\`if statements with conditions that are always false have the effect of making blocks of code non-functional. if statements with conditions that are always true are completely redundant, and make the code less readable.</p>
    </div>

    <div class="paragraph">
      <p>There are three possible causes for the presence of such code:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>An if statement was changed during debugging and that debug code has been committed.</p>
        </li>

        <li>
          <p>Some value was left unset.</p>
        </li>

        <li>
          <p>Some logic is not doing what the programmer thought it did.</p>
        </li>
      </ul>
    </div>

    <div class="paragraph">
      <p>In any of these cases, unconditional if\` statements should be removed.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      if (true) {  
      doSomething(); 
      }
      ...
      if (false) {  
      doSomethingElse(); 
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Empty statements should be removed">
    <div class="paragraph">
      <p>Empty statements represented by a semicolon ; are statements that do not perform any operation. They are often the result of a typo or a misunderstanding of the language syntax.
      It is a good practice to remove empty statements since they don’t add value and lead to confusion and errors.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      function doSomething():void {
      ;                                                       // Noncompliant - was used as a kind of TODO marker
      }

      function doSomethingElse():void {
      trace("Hello, world!");;                     // Noncompliant - double ;
      ...
      for (var i:int = 0; i < 3; trace(i), i++);       // Noncompliant - Rarely, they are used on purpose as the body of a loop. It is a bad practice to have side-effects outside of the loop body
      ...
      }
      ```

      ```flex Fix theme={null}
      function doSomething():void {}

      function doSomethingElse():void {
      trace("Hello, world!");
      ...
      for (var i:int = 0; i < 3; i++){
      trace(i);
      }
      ...
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="switch statements should have default clauses">
    <div class="paragraph">
      <p>The requirement for a final <code>default</code> clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      switch (param) { // Noncompliant - default clause is missing
      case 0:
      doSomething();
      break;
      case 1:
      doSomethingElse();
      break;
      }

      switch (param) {
      default: // Noncompliant - default clause should be the last one
      doSomething();
      break;
      case 0:
      doSomethingElse();
      break;
      }
      ```

      ```flex Fix theme={null}
      switch (param) {
      case 0:
      doSomethingElse();
      break;
      default:
      doSomethingElse();
      break;
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="switch statements should not be nested">
    <div class="paragraph">
      <p>Nested \`switch structures are difficult to understand because you can easily confuse the cases of an inner switch as belonging to an outer statement. Therefore nested switch statements should be avoided.</p>
    </div>

    <div class="paragraph">
      <p>Specifically, you should structure your code to avoid the need for nested switch statements, but if you cannot, then consider moving the inner switch\` to another function.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public function func(foo:Number, bar:Number):void
      {
      switch (foo)
      { 
      case 1:
        // do something
        break;
      case 2:
        switch (bar)  // Noncompliant
        {
          case 89:  // It's easy to lose sight of what's being tested; is it foo or bar?
            // ...
            break;
          case 90:
            // ...
            break;
        }
        break;
      case 3:
        // do something
        break;
      default:
        break;
      }
      }
      ```

      ```flex Fix theme={null}
      public function func(foo:Number, bar:Number):void
      {
      switch (foo)
      { 
      case 1:
        // ...
        break;
      case 2:
        handleBar(bar);
        break;
      case 3:
        // ...
        break;
      default:
        break;
      }
      }

      public function handleBar(bar:Number):void
      {
      switch (bar)
      {
      case 89:
        // ...
        break;
      case 90:
        // ...
        break;
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unused local variables should be removed">
    <div class="paragraph">
      <p>An unused local variable is a variable that has been declared but is not used anywhere in the block of code where it is defined. It is dead code, contributing to unnecessary complexity and leading to confusion when reading the code. Therefore, it should be removed from your code to maintain clarity and efficiency.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public function numberOfMinutes(hours:int):int
      {
      var seconds:int = 0;  // Noncompliant - seconds is unused 
      return hours * 60;
      }
      ```

      ```flex Fix theme={null}
      public function numberOfMinutes(hours:int):int
      {
      return hours * 60;
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Local variable and function parameter names should comply with a naming convention">
    <div class="paragraph">
      <p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
      \{identifier\_capital\_plural} hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
      Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug.
      It also ensures consistency in the code, especially when multiple developers are working on the same project.</p>
    </div>

    <div class="paragraph">
      <p>This rule checks that \{identifier} names match a provided regular expression.</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      public function doSomething(my_param:int):void
      {  
      var LOCAL:int;
      ...
      }
      ```

      ```flex Fix theme={null}
      public function doSomething(myParam):void
      {  
      var local;
      ...
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Public classes, methods, properties and metadata should be documented with ASDoc">
    <div class="paragraph">
      <p>Undocumented APIs pose significant challenges in software development for several reasons:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p><strong>Lack of Clarity:</strong> developers struggling to understand how to use the API correctly. This can lead to misuse and unexpected results.</p>
        </li>

        <li>
          <p><strong>Increased Development Time:</strong> developers spending extra time reading and understanding the source code, which slows down the development process.</p>
        </li>

        <li>
          <p><strong>Error Prone:</strong> developers are more likely to make mistakes that lead to bugs or system crashes when the intent or the error handling of an API is not clear.</p>
        </li>

        <li>
          <p><strong>Difficult Maintenance and Updates:</strong> developers may not understand the existing functionality well enough to add new features without breaking the existing ones.</p>
        </li>

        <li>
          <p><strong>Poor Collaboration:</strong> collaboration, when there is lack of documentation, leads to confusion and inconsistencies.</p>
        </li>
      </ul>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      /**
      * @private  // This class and all its elements are ignored
      */
      public class MyClass {  // Compliant

      public var myLabel:String;   // Compliant
      }

      public class AnotherClass {  // Noncompliant; class not @private and not documented

      /**
      * @private
      */
      public var name:String;  // Compliant
      }
      ```

      ```flex Fix theme={null}
      public class MyClass {
      public var myLabel:String; 

      public function myMethod(param1:String):Boolean {
      // ...
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Local variables should not shadow class fields">
    <div class="paragraph">
      <p>Local variables should not shadow class fields</p>
    </div>

    <CodeGroup>
      ```flex Bad theme={null}
      class Foo {
      public var myField:int;

      public function doSomething():String {
      var myField:int = 0; // Noncompliant
      //...
      }
      }
      ```

      ```flex Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
