Flex中如何利用focusIn和focusOut事件对表单中获得焦点的项目进行颜色高亮(highlight)显示的例子
By Minidxer | September 21, 2008
接下来的例子演示了Flex中如何利用focusIn和focusOut事件,对表单中获得焦点的项目进行颜色高亮(highlight)显示。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Style>
- FormItem {
- paddingLeft: 4;
- paddingRight: 4;
- paddingTop: 4;
- paddingBottom: 4;
- }
- </mx:Style>
- <mx:Script>
- <![CDATA[
- private const BACKGROUND_COLOR:Object = "haloBlue";
- private function formItem_focusIn(evt:FocusEvent):void {
- var item:FormItem = FormItem(evt.currentTarget.parent);
- item.setStyle("backgroundAlpha", 0.2);
- item.setStyle("backgroundColor", BACKGROUND_COLOR);
- }
- private function formItem_focusOut(evt:FocusEvent):void {
- var item:FormItem = FormItem(evt.currentTarget.parent);
- item.setStyle("backgroundColor", null);
- }
- ]]>
- </mx:Script>
- <mx:Form>
- <mx:FormItem label="First name:">
- <mx:TextInput id="firstName"
- focusIn="formItem_focusIn(event);"
- focusOut="formItem_focusOut(event);" />
- </mx:FormItem>
- <mx:FormItem label="Last name:">
- <mx:TextInput id="lastName"
- focusIn="formItem_focusIn(event);"
- focusOut="formItem_focusOut(event);" />
- </mx:FormItem>
- </mx:Form>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Other |
No Comments » |
362 views
Tags: focusIn, focusOut, Form, FormItem