package com.test
{
public
class SealedClassExample
{
public function SealedClassExample()
{
}
private var _name:String;
private var _age:
int;
public var test:String =
"test";
public function set name(val:String):
void
{
this._name = val;
}
public function get name():String
{
return
this._name;
}
public function set age(val:
int):
void
{
this._age = val;
}
public function get age():
int
{
return
this._age;
}
}
}
<?xml version=
"1.0" encoding=
"utf-8"?>
<mx:Application xmlns:mx=
"http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
import com.test.SealedClassExample;
import com.test.DynamicClassExample;
private function testDynamic():void
{
var dy:DynamicClassExample = new DynamicClassExample();
dy.age = 10;
dy.name = "Dynamic"
dy.newAddProp = "Hello,Dynamic class!";
dy.url = "com.test.Dynamic.url";
for( var k in dy)
{
tad.text +=k+":"+dy[k]+"\n";
}
}
private function testSealed():void
{
var seal:SealedClassExample = new SealedClassExample();
seal.age = 10;
seal.name = "seal";
//seal.newAddProp = "You had better not do that!";
//seal.url = "com.test.sealed.url";
// if the below code is not commented,the compiler will indicate the error:access undefined property.
for( var k in seal)
{
tas.text +=k+":"+seal[k]+"\n";
}
}
]]>
</mx:Script>
<mx:HDividedBox width="100%" height="100%" horizontalAlign="left" verticalAlign="top">
<mx:VBox width="50%" height="100%">
<mx:Button label="testDynamic" click="testDynamic()"/>
<mx:TextArea text="" id="tad" width="379" height="460"/>
</mx:VBox>
<mx:VBox width="50%" height="100%">
<mx:Button label="testSealed" click="testSealed()"/>
<mx:TextArea text="" id="tas" width="329" height="470"/> </mx:VBox> </mx:HDividedBox> </mx:Application>