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!"); } }