AS3: When and Why use “final” attribute

To prevent a class from being extended or a method from being overridden, we precede that class or method definition with the final attribute.

How it works?
To Final a class:
final public class A{

}

To Final a method:
public class A{
final public function A{

}

}

The final attribute is used for two reasons in ActionScript:

  • In some situations, final method execute faster than non-final methods. If you are looking to improve your application’s performance in every possible way, try making its method final.
  • Methods that are final help hide a class’s internal detail. Making a class or a method final prevents other programmers from extending the class or overriding the method for the purpose of examining the class’s internal structure. Such prevention is considered one of the ways to safeguard an application from being maliciously exploited.
  • AS3: Recursive Functions vs Loop Functions

    A recursive function is a function that calls itself. The following code shows a simple example of recursion.

    function trouble(){
    trouble();
    }

    A recursive function like above calls itself unconditionally, cause infinite recursion. To prevent this from happening, practical recursion functions call themselves only while a given condition is met.
    Continue reading

    AS 3: Functions as Values

    A function can be assigned to a variable, passed to a function, or returned from a function, just like any other values.

    For example, the following code defines a function, a() and then assigns it to the variable b. Notice that the parentheses operator, (), is omitted; if it were included, the code would simply assign a()’s return value to b.

    function a(){

    }
    var b=a;

    Once a function has been assigned to a variable, it can be invoked through that variable using the standard parentheses operator, (). For example, the following code invokes the function a() through the variable b:

    b();

    Tags support in htmlText flash as3

    1. anchor tag <a> </a>


    Three attributes are supported:

    1.1 href: URL can be relativl or absolute. Notice: the absolute URL must begin with “http://”, otherwise, flash player will regard it as relative URL.

    1.2 target: define the name of target loaded page, options: _self,_blank,_parent,_top;
    _self means current window and current frame
    _blank means open a new window
    _parent means the parent of current frame;
    _top menas the highest frame of the current frame;

    1.3 bold tag <b></b> everything words between <b>xxx</b> will be bold;
    Continue reading