One of the first decisions that you must make when creating custom components is deciding whether to write
them in MXML or in ActionScript. Ultimately, it is the requirements of your application that determine how you
develop your custom component.
Some basic guidelines include the following:•MXML components and ActionScript components both define new ActionScript classes.
•Almost anything that you can do in a custom ActionScript custom component, you can also do in a custom MXML component. However, for simple components, such as components that modify the behavior of an existing component or add a basic feature to an existing component, it is simpler and faster to create them in MXML.
•When your new component is a composite component that contains other components, and you can express the positions and sizes of those other components using one of the Flex layout containers, you should use MXML to define your component.
•To modify the behavior of the component, such as the way a container lays out its children, use ActionScript.
•To create a visual component by creating a subclass from UIComponent, use ActionScript.
•To create a nonvisual component, such as a formatter, validator, or effect, use ActionScript.
•To add logging support to your control, use ActionScript. For more information, see “Logging” on page 227 in Building and Deploying Adobe Flex 3 Applications.
Flex3 官方文档中如上释疑. 2010年我参加Flex Developer Day时, 有开发者提问国内是否有大型企业应用实例? 未得到正面回答. 倒是群硕的团队还上台张扬了一把, 他们的项目大约是奥运时CCTV直播网站.
其实即便国内有大型的企业应用, 也不一定能获得足够价值的经验.
07年底开始做的教育应用, 大致有120W行代码, 其中有60%+的为AS代码, 除了入口文件及部分复杂UI使用MXML之外, 清一色都是AS代码, 所有的UI都小心谨慎的创建, 销毁. 在10年的DevDay时, 坐在我旁边的某研发他们也是纯AS.
几年过去了, Flex贡献给了Apache, Flex也已经4.6了, 接触的代码多了, 习惯了清纯的AS代码, 当满篇都是MXML标签时, 我不淡定了.
思想斗争良久, 到底孰优孰劣? 在多数common的情况下, 几乎不分上下. 我觉得AS代码更优雅更易读, 可人家说了: 我们可以Design, 不用代码, 一眼就看出来了…:(
如上View, 假如我们只用MXML或只用AS来实现, 似乎看不出明显差异来, 其实相比选择编程方式, 可能对组件/Class的划分可能更加重要.
不论用MXML还是AS, Class设计好更加关键:
1.1.1 可以设计成一个Common的组件;
1.1 可以作为一个组合的UserList
2.1/2.2 作为显示用户基本信息的组件;
这样划分, 不论MXML还是AS都可以很好的降低耦合, 更可重用, 但不论如何, 我还是喜欢干净的AS代码.
我一直不喜欢在AS中频繁的操作XML, 但没办法, 最近所有的data都是来自于XML, 没有任何ValueObject, 清一色的XML.
把把都得翻书找手册 🙁 弱到爆
Trace到的结果:
The following table summarizes the results of casting to the Boolean data type from other data types:
Data type or value | Result of conversion to Boolean |
String | false if the value is null or the empty string ( “” ); true otherwise. |
null | false |
Number, int or uint | false if the value is NaN or 0; true otherwise. |
Object | false if the instance is null ; true otherwise. |
Note: when you convert a string to boolean, remeber to trim the string first.
and this is a capture from <<Essential ActionScript 3.0>>:
FlashPlayer provide a cool local storage mechanism called ‘SharedObject’, we can store some user info in user local machine. for example, douban.fm store the last channel in sharedObject.
You can check the local storage setting for current domain by right click, or check all setting from Control Panel>FlashPlayer, additionally, you can manage all settings by this: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager07.html
Flashplayer need the user configure this setting manually, but some times we want change the setting automatically, especially for some enterprise application, like E-Learning, Banking, HIS.
Currently, I did not found any API or workaround to change the local storage automatically 🙁
I just write a small tool to check the local storage setting directly, >>Link<<
(you may download and upload this swf to your server if needed)
/** * Check local storage setting. */ protected function checkLocalStorage(event:MouseEvent):void { var sharedObjectForTest:SharedObject = SharedObject.getLocal("sharedObjectTest", "/"); sharedObjectForTest.addEventListener(NetStatusEvent.NET_STATUS, onSharedObjectEvent); sharedObjectForTest.data.result = "OK"; try { var result:String = sharedObjectForTest.flush(); if(result == SharedObjectFlushStatus.FLUSHED) { traceLog("OK, and currect size is: " + sharedObjectForTest.size); }else { traceLog("Failed, and the Flashplayer security setting panel is shown."); } } catch(error:Error) { traceLog("Error, and show the seeting panel manually;"); Security.showSettings(SecurityPanel.LOCAL_STORAGE); } }
Here is the XML:
<XeSex sexIDElement='MID'> <SexID> M </SexID> <Name> Male </Name> <Active> y </Active> <Code> M </Code> </XeSex>
Attitude: sexIDElement = ‘MID’;
Element: Name = Male
trace(xmlTest.hasOwnProperty('@sexIDElement')); // check if the attribute exists trace(xmlTest.hasOwnProperty('Name')); // check if the element exists
BTW, About: XML Elements vs. Attributes
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.