? Canvas应该是大家在开发flex接触比较多控件吧,但是它的功能比较单一,很多人都要给予2次开发,我也是一样,为了做好延时的flex控件异步加载。一个巨大的flex整体切割成为很多很小很小的swf,就要做了一个延时加载。每个Canvas都有。
- <?xml?version="1.0"?encoding="utf-8"?>??
-
<mx:Canvas?xmlns:mx="http://www.adobe.com/2006/mxml"??
-
???????????initialize="loadInit()"??
-
???????????backgroundColor="0xffffff">??
- ????<mx:Script>??
- ????????<!--[CDATA[??
-
????????????import?mx.controls.Image;??
-
????????????import?mx.controls.Alert;??
- ??
-
????????????import?flash.utils.setTimeout;??
- ??
-
????????????import?org.bytearray.gif.player.GIFPlayer;??
- ??
-
??????????????
-
????????????public?var?autoRefreshPolicy="off";??
-
????????????public?var?autoRefreshTime:String="60000";??
-
????????????public?var?autoRefreshMethod:Function;??
- ??
-
????????????private?var?loading:Image;??
-
????????????private?var?myGIFPlayer:GIFPlayer=new?GIFPlayer(true);??
- ??
-
????????????public?var?gifUrl:String="resource/image/config/canvasLoading.gif";??
- ??
-
??????????????
-
????????????private?var?oldIndex:int=0;??
-
????????????public?var?moveable:Boolean=false;??
- ??
-
????????????public?function?loadInit():void??
- ????????????{??
-
????????????????loading=new?Image;??
-
????????????????loading.width=50;??
-
????????????????loading.height=50;??
-
????????????????loading.x=0;??
-
????????????????loading.y=0;??
- ??
-
????????????????var?request:URLRequest=new?URLRequest(gifUrl);??
- ????????????????myGIFPlayer.load(request);??
-
????????????????myGIFPlayer.visible=true;??
- ??
- ????????????????loading.addChild(myGIFPlayer);??
-
????????????????this.addChild(loading);??
-
????????????????this.enabled=false;??
- ??
-
????????????????if?(autoRefreshPolicy?==?"on")??
- ????????????????{??
-
????????????????????setTimeout(autoRefresh,?800);??
- ????????????????}??
- ??
-
????????????????this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,?dragBegin);??
-
????????????????this.addEventListener(flash.events.MouseEvent.MOUSE_UP,?dragEnd);??
- ????????????}??
- ??
-
????????????public?function?autoRefresh():void??
- ????????????{??
-
????????????????var?time:Number=Number(autoRefreshTime)?*?1000;??
-
????????????????var?timer:Timer=new?Timer(time);??
- ????????????????timer.addEventListener(TimerEvent.TIMER,?onTimer);??
- ????????????????timer.start();??
- ????????????}??
- ??
- ??
-
????????????public?function?onTimer(event:TimerEvent):void??
- ????????????{??
-
????????????????if?(autoRefreshMethod?!=?null)??
- ????????????????{??
-
????????????????????autoRefreshMethod.call(this);??
- ????????????????}??
-
????????????????else??
- ????????????????{??
-
????????????????????Alert.show("自动刷新函数为空");??
- ????????????????}??
- ????????????}??
- ??
- ??
-
????????????public?function?startLoading():void??
- ????????????{??
-
????????????????loading.visible=true;??
-
????????????????this.enabled=false;??
- ????????????}??
- ??
-
????????????public?function?completeLoading():void??
- ????????????{??
-
????????????????loading.visible=false;??
-
????????????????this.enabled=true;??
- ????????????}??
- ??
-
????????????private?function?dragBegin(event:MouseEvent):void??
- ????????????{??
-
????????????????if?(moveable?==?true)??
- ????????????????{??
-
????????????????????oldIndex=this.parent.getChildIndex(this);??
-
????????????????????this.parent.setChildIndex(this,?this.parent.numChildren?-?1);??
-
????????????????????this.startDrag(false);??
- ????????????????}??
- ????????????}??
- ??
-
????????????private?function?dragEnd(event:MouseEvent):void??
- ????????????{??
-
????????????????if?(moveable?==?true)??
- ????????????????{??
-
????????????????????this.parent.setChildIndex(this,?oldIndex);??
-
????????????????????this.stopDrag();??
- ????????????????}??
- ????????????}??
- ??
-
??????????????
-
????????????protected?function?delayFunction(closure:Function,?delay:Number,?...?arguments):void??
- ????????????{??
- ????????????????setTimeout(closure,?delay,?arguments);??
- ????????????}??
- ????????]]-->??
- ????</mx:Script>??
- </mx:Canvas>??
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|