sampleconstructor.as

来自「《Flash AS3殿堂之路》光盘源码 学习ActionScript 3.0」· AS 代码 · 共 49 行

AS
49
字号
package org.kingda.book.basicoop
{
	import flash.display.Sprite;

	public class SampleConstructor extends Sprite
	{
		public function SampleConstructor() {
			var foo:Foo = new Foo();
			trace (foo);
			//输出:[object Foo]
			var bar:Bar = new Bar("ActionScript 3");
			/*输出:
			Bar's constructor!
			init executed!
			*/
			trace (bar);			
			//输出:[object Bar]
			trace (bar.isOK);
			trace (bar.hello);
			//输出:true			
		}
	}
}
class Foo {
	public function Foo() {
		trace ("Foo's constructor!!");
		return;
		trace ("We cannot see this trace");
	}
}
class Bar {
	public var isOK:Boolean;
	public var hello:String;
	public function Bar(hS:String) {
		trace ("Bar's constructor!!");
		isOK = true;
		hello = hS;		//将构造函数的参数赋值给实例属性hello
		init();
		return;
		trace ("We cannot see this trace, cause it is after 'return'");
	}
	
	function init():void {
		trace ("init executed!");
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?