使用ActionScript做Render时一般都会重写set data以实现具体效果, 洒家每次犯过多次低级错误, 那便是忘记set data时super之.
忘记super的后果是数据可能不会正常显示, Datagrid可能在浮动/点击 Render时 所在行没反应.
显示不正常的, 如: http://liguoliang.com/2009/10/1071/
附: 重写Box作为ItemRender代码(该类作为一个抽象出来专用于重写的Abstract类, 所以并未实现具体效果):
/* * $Id$ * Copyright (c) 2008-2010 Insprise Software (Shanghai) Co. Ltd. * All Rights Reserved * Changelog: * LiGuoliang.com - Aug 15, 2010: Initial version */ package com.insprise.util.speedtest.lib { /** * SpeedTester的速度Render. */ [ResourceBundle('canvas_main')] public class AbstractRenderForSpeed extends Box implements IDropInListItemRenderer, IListItemRenderer { public static const RM:IResourceManager = ResourceManager.getInstance(); public static const BUNDLE_CANVAS_MAIN:String = "canvas_main"; /** Data */ protected var _speedTester:SpeedTester; // 当前数据 /** UI */ protected var _progressBar:ProgressBar; protected var numberFormatter:NumberFormatter = SpeedTesterUtils.getNumFormatterForSpped(); private var _listData:BaseListData; // 为实现IDropInListItemRenderer而创建. // Constructor public function AbstractRenderForSpeed() { super(); direction = BoxDirection.HORIZONTAL; // 设置Box方向 } /** @inheritDoc */ public function get listData():BaseListData { return _listData; } /** @inheritDoc */ public function set listData(value:BaseListData):void { _listData = value; } /** @inheritDoc */ override protected function createChildren():void { _progressBar = new ProgressBar(); _progressBar.mode = ProgressBarMode.MANUAL; // 设置Mode为手动, 以手动设置进度 _progressBar.labelPlacement = ProgressBarLabelPlacement.CENTER; // 设置Label位置 addChild(_progressBar); } /** @inheritDoc */ override public function set data(value:Object):void { super.data = value; // 不能忘啊不能忘! if(_speedTester == value) { return; } _speedTester = value as SpeedTester; updateUI....; // 更新UI等操作 } } // end class } // end package
Flex 中使用ProgressBar / Using ProgressBar in Flex <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.