Actionscript 3
  • Block-level scope in ActionScript 3.0
    • A block of code is any group of statements between an opening curly brace ( { ) and a closing curly brace ( })
    • In some programming languages, such as C++ and Java, variables declared inside a block of code are not available outside that block of code. This restriction of scope is called block-level scope, but the case is different in ActionScript 3.0, it doesn't support block-level scope.
  • It only contains the compiled ActionScript 3.0 byte code, which is also known as ABC.
  • It is a compiled clip that holds all of the precompiled byte code for every definition in the User Interface Component Infrastructure.
  • The user does not need the ActionScript files for these classes and other definitions in the classpath because of the ComponentShim.
  • If the user does have the User Interface ActionScript files in his classpath, then the ActionScript 3.0 compiler will prefer the definitions in those files over the precompiled definitions in ComponentShim. You can debug the source file and you can make changes to it.
  • Event Handle
  • flash.events.EventDispatcher
    • addEventListener()
  • Using listenerObject
var lo:Object = new Object();
lo.click = function(evt){
    // this refers to the object lo
    trace(this);
}
myButton.addEventListener("click", lo);
  • Using the this keyword as the listener object
function eventName(evtObj:Object){
    // code placed here executes
    // when the event is triggered
}
componentInstance.addEventListener("eventName", this);
  • Using listener function
myList.addEventListener("change", myChangeHandler);
myList.addEventListener("scroll", myScrollHandler);
To use a listener function, you must first define a function:

function myFunction:Function(evtObj:Object){
    // your code here 
}
  • Using the handleEvent callback function
function handleEvent(evt){
    // check if the event was a click
    if (evt.type == "click"){
        // do something if the event was click
    } else if (evt.type == "change"){
        // do something else if the event was change
    }
};

instance.addEventListener("click", this);
instance2.addEventListener("change", this);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License