Bom nas últimas turmas de ActionScript tenho mostrado que a linguagem não fica presa ao Flash, mas também pode ser aplicada ao Flex e ao Air, e uma pergunta tem rolado com frequencia. "Não da para mudar o pre-loader do Flex não?!". Bom a Resposta é sim, da para mudar. Abaixo segue uma classe que escrevi para realizar tão ardua tarefa, basta mudar o apontamento para o swf que será usado como loader e talvez mudar os nomes dos elementos que serão responsáveis pelo ProgressEvent.
1: package ascomp.core.loader {2: import flash.display.Loader;3: import flash.display.MovieClip;4: import flash.display.Sprite;5: import flash.events.Event;6: import flash.events.ProgressEvent;7: import flash.events.TimerEvent;8: import flash.net.URLRequest;9: import flash.utils.Timer;10:11: import mx.events.FlexEvent;12: import mx.preloaders.IPreloaderDisplay;13:14: public class PreLoader extends Sprite implements IPreloaderDisplay {15: private var dpbImageControl:Loader;16: private const fileLoaderPath:String = "ascomp/core/loader/loaderDisplay.swf";17:18: public function PreLoader() {19: super();20: }21:22: public function set preloader(preloader:Sprite):void {23: preloader.addEventListener(ProgressEvent.PROGRESS, handleProgress);24: preloader.addEventListener(Event.COMPLETE, handleComplete);25: preloader.addEventListener(FlexEvent.INIT_PROGRESS, handleInitProgress);26: preloader.addEventListener(FlexEvent.INIT_COMPLETE, handleInitComplete);27: }28:29: public function initialize():void {30: dpbImageControl = new Loader();31: dpbImageControl.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);32: dpbImageControl.load(new URLRequest(fileLoaderPath));33: }34:35: private function loaderCompleteHandler(evt:Event):void {36: this.addChild(dpbImageControl);37: dpbImageControl.x = (this.stage.stageWidth - dpbImageControl.width) / 2;38: dpbImageControl.y = (this.stage.stageHeight - dpbImageControl.height) / 2;39: }40:41: private function handleProgress(evt:ProgressEvent):void {42: try {43: var objMC:MovieClip = MovieClip(dpbImageControl.content);44: objMC.lDisplay.loaderBar.scaleX = evt.bytesLoaded / evt.bytesTotal * 1;45: objMC.lDisplay.loaderText.text = "Carregando... " + Number(evt.bytesLoaded / evt.bytesTotal * 100).toFixed(2) + "%";46:47: }48: catch(err:Error) {}49: }50:51: private function handleComplete(evt:Event):void {52: }53:54: private function handleInitProgress(evt:Event):void {55: }56:57: private function handleInitComplete(evt:Event):void {58: var timer:Timer = new Timer(2000,1);59: timer.addEventListener(TimerEvent.TIMER, dispatchComplete);60: timer.start();61: }62:63: private function dispatchComplete(evt:TimerEvent):void {64: dispatchEvent(new Event(Event.COMPLETE));65: }66:67: public function get backgroundColor():uint {68: return 0;69: }70:71: public function set backgroundColor(value:uint):void {72: }73:74: public function get backgroundAlpha():Number {75: return 0;76: }77:78: public function set backgroundAlpha(value:Number):void {79: }80:81: public function get backgroundImage():Object {82: return undefined;83: }84:85: public function set backgroundImage(value:Object):void {86: }87:88: public function get backgroundSize():String {89: return "";90: }91:92: public function set backgroundSize(value:String):void {93: }94:95: public function get stageWidth():Number {96: return 200;97: }98:99: public function set stageWidth(value:Number):void {100: }101:102: public function get stageHeight():Number {103: return 200;104: }105:106: public function set stageHeight(value:Number):void {107: }108: }109: }110:
Nenhum comentário:
Postar um comentário