Inhaltsverzeichnis

ActionScript

ActionScript ist die Script-Sprache der Flash-Plattform. Sie existiert in drei Versionen, wobei sich ActionScript 1.0 und ActionScript 2.0 sehr ähnlich sind; ActionScript 3.0 ist eine komplette Neu-Entwicklung der Sprache mit Objekt-Orientierung.

Hello World

„Hello World“-Beispiel in ActionScript 3.0:

HelloWorld.as
package {
	public class HelloWorld {
		public function HelloWorld() {
			trace("Hello World!");
		}
	}
}

"Hello World"-Beispiel auf GitHub

Code-Konventionen

Beispiel-Klasse

example.as
package {
	import flash.display.Sprite;
 
	/**
	 * Example class
	 *
	 * This is an example class in ActionScript 3.0 with some basic code conventions.
	 *
	 * @author Foo Bar <foo.bar@example.com>
	 * @date 2011-10-24
	 * @edit 2012-10-25 Foo Bar <foo.bar@example.com>
	 */
	public class Example extends Sprite {
		//
		// Constants
		//
 
		private static const FOO_BAR:Boolean = true;
 
		//
		// Variables
		//
 
		// Public variables
 
		public var foobar:String;
 
		// Protected variables
 
		protected var barfoo:String;
 
		// Private variables
 
		private var bar:String;
 
		// Private variables for properties
 
		private var _foo:String;
 
		//
		// Constructor
		//
 
		public function Example() {
		}
 
		//
		// Properties
		//
 
		public function get foo():String {
			return this._foo;
		}
 
		public function set foo(value:String):void {
			this._foo = value;
		}
 
		//
		// Methods
		//
	}
}

Variablen

Globale Variablen werden wie lokale Variablen benannt, ohne besonderen Präfix. Außer globale Variablen für Eigenschaften: Diese heißen exakt so wie die Eigenschaft, haben aber einen Unterstrich als Prefix.

FlashVars

Einzelne FlashVar auslesen

private function getFlashVar(key:String):String {
	var value:String = "";
 
	if (this.loaderInfo.parameters.hasOwnProperty(key)) {
		value = this.loaderInfo.parameters[key] as String;
	}
 
	return value;
}