Showing posts with label AS3. Show all posts
Showing posts with label AS3. Show all posts

Sunday, May 23, 2010

Reading note of 'Real world flash game development'

Chapter 3:
A Quick Review of the Planning Steps
● One- to two-sentence description
● Game screen wireframe and fl ow
● List of game mechanics
● List of assets (art, animation, sound, video, and copy)
● Technical requirements
● UML class diagrams

Chapter 4:
传入任意数量参数到函数/方法

function myFunction (… params):void {
for (var i:int = 0; I < params.length; i + + ) {
if (!(params[i] is DisplayObject)) {
throw new ArgumentError( “ Only DisplayObjects can be used in myFunction. ” );
}
}
}


Getter/Setter

package {
public class MyClass {
protected var _maxNameLength:int = 8;
protected var _name:String;
protected var _lives:int = 3;
public function get name():String {
return _name;
}
public function set name(value:String):void {
name = value.substr(0,maxNameLength);
}
public function get lives():int {
return _lives;
}
}
}
//OUTSIDE CLASS
var myInstance:MyClass = new MyClass();
myInstance .name = “ CHRISTOPHER ” ;
trace (myInstance.name); //OUTPUTS “ CHRISTOP ” ;
trace (myInstance.lives); //OUTPUTS 3;
myInstance .lives = 10; //THROWS ERROR


to be Continued.

Friday, April 24, 2009

Flex3/ActionScript3.0中eval的替代方案

AS3中没有eval,但可以像这样调用:

this["your_function_name"]();


请看例子:


private function playTrack(location:String):void {

var dot_position:Number = location.lastIndexOf('.');
var file_ext:String = location.substr(dot_position+1);

var play_function_name:String = file_ext+"_player";
if (this.hasOwnProperty(play_function_name)) {
this[play_function_name]();
}else {
Alert.show("Do not support this file extension("+file_ext+").");
}

}


参考:http://livedocs.adobe.com/flex/3/html/help.html?content=ProgrammingHTMLAndJavaScript_03.html