Friday, December 19, 2008

ActionScript 3 notes

=== Data types ===

Top level types:

- void, int, uint,
- Object, Number, String, Boolean, Null


Complex types:

- Date, Array, ByteArray, Vector, Dictionary, RegExp, Function, Error
- XML, XMLList, BitMap, Shape, MovieClip, Video, SimpleButton, TextField



=== Declaration ===:

Package, import, class:

package com.example {
import flash.net.URLLoader;
import flash.net.URLRequest;
public class Example {
// Class code goes here.
}
}


Access modifiers:

public : accessible outside the class (e.g., from an instance of the class).
private : accessible only within the class.
protected : accessible only within the class and its subclasses.
internal : accessible only within the package.


Variable/constant, field/property:

var myObject: Object = {Param1:"Hi!", Param2:76};
public var myString: String = "ABC";
protected var myNumber: Number = 5;
private var myInt: int = 12;
var myBoolean: Boolean = true;
var myArray: Array = [5,"Hello!",{a:5, b:7}]
private var myDate: Date = new Date();
var myButton: mx.controls.Button = new mx.controls.Button();
static public const MY_TEST: String = "test constant";

var authorsByBook:Object = new Object( );
authorsByBook["Flex"] = "Mediocre, Ninja";
authorsByBook["ActionScript 3"] = "bibo, ninja, mediocre";



Function/method/constructor:

function test( ):void {
var message:String = "function message";
trace(message);
}




=== Formal syntax ===

Expression/Statement/FlowControl

while(total < int =" 0;"> maxTotal + 20) {
total -= 10;
}
else {
total -= 5;
}



Inheritance

package com.example {
import com.example.A;
public class B extends A {
override public function run( ):void {
trace("B");
}
}
}


Interface

package com.example {
public interface IExample {
function a( ):String;
function b(one:String, two:uint):void;
}
}

package com.example {
import com.example.IExample;
public class Example implements IExample {
public function Example( ) {
}
public function a( ):String {
return "a";
}
public function b(one:String, two:uint):void {
trace(one + " " + two);
}
}
}


Handling Event

;lt&mx:Script;gt&
;lt&![CDATA[
import flash.net.FileReference;
private function initializeHandler(event:Event):void {
var file:FileReference = new FileReference( );
file.browse( );
file.browse( );
}
]];gt&
;lt&/mx:Script;gt&


Handling Error

try {
// Code that might throw errors
}
catch (error:IOError) {
// Code in case the specific error occurs
}
catch (error:Error) {
// Code in case a non-specific error occurs
}
finally {
// Code to run in any case
}




(to be updated)

No comments: