先描述一下作品的需求:
滚动新闻作为当前ViewStack的其中一页,要实现定时刷新。
单纯的滚动新闻效果,相信大家都很容易实现,不过就是通过设置Move的一些属性罢了,
//滚动字幕
private function moveAction():void{
if(recordsNum>DEFAULT_SCROLL_ROWNUM){
move_up.end(); //这句话 最好加 否则会在HttpService刷新数据时 产生其他效果
move_up.yFrom = 0;
move_up.yTo = 0-AbfltDG.height;
move_up.repeatCount = 0; //loop
move_up.repeatDelay = 0; //loop time
move_up.duration = SPEED_SCROLL*recordsNum; //the time of scroll once 其中SPEED_SCROLL、
recordsNum都是自定义的变量Number类型
move_up.play();
}
}
<!--相应页面元素-->
<mx:Move id="move_up" target="{AbfltDG}"/>
<mx:Canvas x="310" y="265" width="670" height="450" id="canvas_dg" horizontalScrollPolicy="off" verticalScrollPolicy="off" mouseOver="move_pause()" mouseOut="move_resume()" backgroundColor="#90C3FC">
<mx:DataGrid x="0" y="0" width="670" height="500" id="AbfltDG" dataProvider="{fltdata}" verticalScrollPolicy="off" showHeaders="false" verticalGridLines="true" styleName="ABFlt" visible="false" backgroundColor="#90C3FC" backgroundAlpha="0.9">
<mx:columns>
<mx:DataGridColumn headerText="航站" dataField="stationName" textAlign="center" fontFamily="宋体" fontSize="12" itemRenderer="sim.monitor.asobj.CustomBackgroundComp"/>
<mx:DataGridColumn headerText="航班号" dataField="fltNumber" textAlign="center" fontFamily="宋体" fontSize="12" itemRenderer="sim.monitor.asobj.CustomBackgroundComp"/>
<mx:DataGridColumn headerText="延误时间" dataField="delayTime" textAlign="center" fontFamily="宋体" fontSize="12" itemRenderer="sim.monitor.asobj.CustomBackgroundComp"/>
<mx:DataGridColumn headerText="延误原因" dataField="delayReason" textAlign="center" fontFamily="宋体" fontSize="12" itemRenderer="sim.monitor.asobj.CustomBackgroundComp"/>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
然而,为了实现在ViewStack中的定时刷新,就要考虑一下界面效果的问题了:
第一、如果不考虑刷新时间,将会造成数据在滚动的过程中刷新;
第二、如果把滚动新闻效果页作为一个独立的控件,如何在ViewStack中访问它,并控制好每次在滚动结束时,根据刷新策略来进行组件的刷新;
这两个问题有些棘手,好在经过思考和查阅,想到了对策!