flex 3 动态标识"dynamic"的使用
前几天刚看过c# 4.0新特性,貌似c# 直到4.0才有的dynamic关键字
flex 3如何使用dynamic
先创建个EmployeeRecord.as,在empty目录下
package empty
{
public dynamic class EmployeeRecord
{
}
}
调用类中,先引入上述类后
在程序中
var emp:EmployeeRecord = new EmployeeRecord();
emp.name = "云飞扬";//添加新属性name
emp.age = 28;//添加新属性age
emp.address = "###路###号";//添加新属性address
emp.city = "杭州";//添加新属性city
emp.state = "HZ";//添加新属性state
emp.zip = "310012";//添加新属性zip
完整调用代码,还要包含有上面的EmployeeRecord.as
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
viewSourceURL=""
horizontalAlign="center" verticalAlign="middle"
width="100%" height="100%"
>
<mx:Script>
<![CDATA[
import empty.EmployeeRecord;
private function showProperties():void
{
var emp:EmployeeRecord = new EmployeeRecord();
emp.name = "云飞扬";//添加新属性name
emp.age = 28;//添加新属性age
emp.address = "###路###号";//添加新属性address
emp.city = "杭州";//添加新属性city
emp.state = "HZ";//添加新属性state
emp.zip = "310012";//添加新属性zip
var displayInfo:Function =
function ():String
{
var str:String;
str = "Employee Record:\n";
str += "Name: " + emp.name + "\n";
str += "Age: " + emp.age + "\n";
str += "Address: " + emp.address + "\n";
str += "City: " + emp.city + "\n";
str += "State: " + emp.state + "\n";
str += "Zip: " + emp.zip + "\n";
return str;
}
emp.displayRecord = displayInfo;
panelPropertyArea.text = emp.displayRecord();
}
]]>
</mx:Script>
<mx:Panel id="panel" title="A Simple Use of Package" status="Active"
height="75%" width="75%"
paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5">
<mx:Label width="100%" color="blue"
text="Program Execution Result: "/>
<mx:TextArea id="panelPropertyArea" width="100%" height="100%"/>
<mx:Button label="Click to Run Program" click="showProperties();"/>
</mx:Panel>
</mx:Application>
原创文章转载请注明出处:云飞扬IT的blog





