More Related Content
Similar to 简化复杂的Flash应用程序 谈熠
Similar to 简化复杂的Flash应用程序 谈熠 (15)
More from FLASH开发者交流会 (20)
简化复杂的Flash应用程序 谈熠
- 4. 数据模型 和 E4X E4X:一个类似Xpath,针对XML数据检索方法 语法简单,速度快 适用的情况: XMLSOCKET XML为基础的HTTP服务或者文件服务 思路:XML、XMLLIST直接作为数据模型(Models)
- 5. varthePeople:XML =<people> <person name="Mims Wright" suffix="III"> <age>27</age> <aka>Mims H Wright</aka> <aka>TehAWesoeomes!</aka> <bio><!--[CDATA[This guy <b>rulz<b>!]]--></bio> </person> <person name="Roger Braunstein"> <age>26</age> <aka>Rog</aka> <aka>That guy</aka> <bio><!--[CDATA[Likes food.]]--></bio> </person> </people>;
- 6. E4X的用例 thePeople.person.age // 得到:<age>27</age> <age>26</age> thePeople.person.@name // 得到:XMLList: Mims Wright, Roger Braunstein thePeople.person.(age >= 21) // 得到: <person name="Mims Wright" suffix="III"> <age>27</age> <aka>Mims H Wright</aka> <aka>TehAWesoeomes!</aka> <bio><!--[CDATA[This guy <b>rulz<b>!]]--></bio> </person>
- 14. 反射的应用 classApplicationState { publicstaticconstLOGIN:uint=1; publicstaticconstLOADING:uint=2; publicstaticconstPLAYING:uint=3; privatestaticconststateNames:Object= {}; }
- 15. 反射的应用 classApplicationState { ... publicstaticfunction init():void { for each(varconstantName:XMLin describeType(ApplicationState).constant.@name) { stateNames[ApplicationState[constantName.toString()]]= constantName.toString(); } } } ...
- 18. 概念1:干 干 —— 避免重复 DRY – Don’t Repeat Yourself 一种常见的重复操作: trace(“name:”+this.name+”, data:”+this.data);……
- 19. 反射在调试时的应用 class Inspector /** * 列出一个对象中的所有公开变量名,并把这些变量名放在一个 Vector.<String> * 容器中 * @paramobj object of any kind * @return 列出一个对象中的所有公开变量名,并把这些变量名放在一个 * Vector.<String> 容器中 */ publicstaticfunctionlistInstanceVariables(obj:*):Vector.<String> { returnxmlListToStringList(describeType(obj).variable.@name); } publicstaticfunctiondumpInstanceVariables(obj:*):Vector.<String> { returndumpProperty(listInstanceVariables(obj),obj); }
- 21. 方法缺失 (Method Missing) 工具:flash.utils.Proxy 作用:重载AS对象默认的操作行为 原理: Object extends flash.utils.Proxy Object.methodName(arg0,arg1) Object.callProperty(“methodName”,args)
- 22. 方法缺失 public dynamic class ClassA extends Proxy { flash_proxy override function callProperty(name:*, ...rest):* { trace(“请求调用方法:”+name) } } varinstanceA:ClassA = new ClassA(); instanceA.doSomeThing(); // 请求调用方法:doSomeThing
- 29. 采用代理模式(Proxy Pattern) Server send() ServerProxy@connectionObject send() RealConnectionsend() RealConnection可能是 xml, json, bin socket, restful http … function send(){ connectionObject.send() }