今天拜读了X先生的作品,深受其益

以下为其主程

//Created by Mr.x 先生 QQ:1300299393
package {
    import flash.utils.*;
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.filters.*;
    import flash.net.*;
    import flash.ui.*;

    public class siteLabuat extends MovieClip {

        private var velocidadFijaCamara:Number = 0
        public var stage_pastilla:MovieClip//instance name
        private var pistasCamara:Array
        public var stage_fondo:MovieClip//instance name
        private var fondo:Shape
        private var bitmapDataFondo:BitmapData
        private var elReproductor:Reproductor
        private var pistasBrillo:Array
        public var stage_cargando:cargando//instance name
        public var stage_canvas:MovieClip//instance name
        private var dondeEstaba:int = 0
        private var timerCamara:Timer
        private var transFondo:Matrix
        public var stage_marco:MovieClip//instance name
        private var pistasLateral:Array
        public var stage_logo:MovieClip//instance name
        private var elDibujante:dibujante
        private var yAnterior:Number = 0
        private var anguloActual:Number = 0
        private var cursor:Sprite
        private var xAnterior:Number = 0
        public var stage_credits:creditos//instance name
        private var realCamarax:Number = 0
        private var realCamaray:Number = 0
        public var stage_reproductor:Reproductor//instance name

        public static const velocidadVariableCamara:Number = 0;
        public static const brilloMinimo:Number = 0.11;
        public static const lateralMinimo:Number = 0.5;
        public static const lateralVariable:Number = 0.5;
        public static const elasticidadCamara:Number = 8;
        public static const brilloVariable:Number = 0.4;
        public static const velocidadMaximaCamara:Number = 46;
        public static const sincronizacionCamara:Number = 0.1;
        public static const velocidadMinimaCamara:Number = 8;

        public static var fondoClip:MovieClip;
        public static var sigueMouse:Boolean = true;
        public static var referenciaY:Number = 0;
        public static var grabando:Boolean = true;
        public static var elDisparadorXML:interpreteXML;
        public static var acelera:Number = 1;
        public static var referenciaX:Number = 0;
        public static var camarax:Number = 0;
        public static var camaray:Number = 0;
        public static var setup:XML;
        public static var stage:Stage;
        public static var elInterprete:interpreteAudio;

        public function siteLabuat():void{
            addFrameScript(0, frame1, 3, frame4, 34, frame35, 36, frame37, 63, frame64, 79, frame80, 88, frame89, 120, frame121, 130, frame131);
            this.stage.align = "TL";
            this.stage.scaleMode = "noScale";
            siteLabuat.stage = this.stage;
            this.stage.quality = "low";
            this.timerCamara = new Timer((siteLabuat.sincronizacionCamara * 1000));
            this.timerCamara.addEventListener(TimerEvent.TIMER, this.sincronizaCamara);
            this.stage.addEventListener(Event.RESIZE, this.redimensiona);
            this.stage_logo.addEventListener(MouseEvent.CLICK, toggleFullScreen);
            this.stage_logo.buttonMode = true;
            this.redimensiona();
            this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, this.movieLoadProgress);
            this.loaderInfo.addEventListener(Event.COMPLETE, this.movieLoadComplete);
            this.cursor = new Cursor();
        }
        function frame89(){
            this.stop();
        }
        private function backgroundLoadProgress(_arg1:ProgressEvent):void{
            var _local2:Number = (_arg1.bytesLoaded / _arg1.bytesTotal);
        }
        public function playable():void{
            siteLabuat.elDisparadorXML = new interpreteXML(siteLabuat.setup.eventos.evento);
            this.elDibujante.borra();
            var _local1:MovieClip = this.elDibujante.nuevoClip("BTPlay", (this.stage.stageWidth / 2), (this.stage.stageHeight / 2));
            this.redimensiona();
            _local1.buttonMode = true;
            _local1.addEventListener(MouseEvent.CLICK, this.go);
            this.stage_credits.pliega();
        }
        function frame37(){
            this.iniciaCargaMedia();
            this.stop();
        }
        private function movieLoadProgress(_arg1:ProgressEvent):void{
            var _local2:Number = (_arg1.bytesLoaded / _arg1.bytesTotal);
        }
        private function backgroundLoadComplete(_arg1:Event):void{
            var _local2:Loader = (_arg1.target as LoaderInfo).loader;
            this.bitmapDataFondo = (_local2.content as Bitmap).bitmapData.clone();
            this.transFondo = new Matrix();
            this.fondo = new Shape();
            this.stage_fondo.addChildAt(this.fondo, 1);
            this.dibujaFondo();
            this.play();
        }
        public function reanuda():void{
            this.timerCamara.start();
            this.addEventListener(Event.ENTER_FRAME, this.tick);
            this.elDibujante.empieza();
            this.elReproductor.empieza();
            siteLabuat.elInterprete.reproduce((this.dondeEstaba / 1000));
            siteLabuat.elDisparadorXML.empieza((this.dondeEstaba / 1000));
            dibujante.inicioGrabacion = (getTimer() - this.dondeEstaba);
        }
        public function empieza():void{
            this.timerCamara.start();
            dibujante.presion = 1;
            siteLabuat.acelera = 1;
            siteLabuat.sigueMouse = true;
            this.addEventListener(Event.ENTER_FRAME, this.tick);
            this.elDibujante.alCentro();
            this.elDibujante.empieza();
            this.elReproductor.empieza();
            siteLabuat.elDisparadorXML.empieza(0);
            if (siteLabuat.grabando){
                this.addChild(this.cursor);
                Mouse.hide();
            };
        }
        private function sincronizaCamara(_arg1:Event):void{
            this.velocidadFijaCamara = ((siteLabuat.velocidadMinimaCamara + ((siteLabuat.velocidadMaximaCamara - siteLabuat.velocidadMinimaCamara) * siteLabuat.elInterprete.volumenPistas(this.pistasCamara))) * siteLabuat.acelera);
        }
        private function iniciaCargaMedia():void{
            siteLabuat.fondoClip = this.stage_fondo;
            this.elReproductor = this.stage_reproductor;
            var _local1:String = siteLabuat.setup.media.audio.cancion;
            var _local2:Array = [];
            var _local3:int;
            while (_local3 < siteLabuat.setup.media.audio.pistas.pista.length()) {
                _local2[_local2.length] = siteLabuat.setup.media.audio.pistas.pista[_local3].toString();
                _local3++;
            };
            siteLabuat.elInterprete = new interpreteAudio(_local1, _local2);
            siteLabuat.elInterprete.addEventListener(ProgressEvent.PROGRESS, this.cancionCargando);
            siteLabuat.elInterprete.addEventListener(Event.COMPLETE, this.cancionCargada);
            siteLabuat.elInterprete.carga();
        }
        function frame121(){
            this.playable();
        }
        public function pausa():void{
            this.dondeEstaba = (getTimer() - elDisparadorXML.inicio);
            this.timerCamara.stop();
            this.removeEventListener(Event.ENTER_FRAME, this.tick);
            siteLabuat.elInterprete.para();
            this.elDibujante.para();
            this.elReproductor.para();
            siteLabuat.elDisparadorXML.para();
        }
        private function movieLoadComplete(_arg1:Event):void{
            var _local2:URLRequest = new URLRequest("setup.xml");
            var _local3:URLLoader = new URLLoader(_local2);
            _local3.load(_local2);
            _local3.addEventListener(Event.COMPLETE, this.XMLCargado, false, 0, true);
            this.redimensiona();
        }
        function frame80(){
            this.redimensiona();
        }
        private function tick(_arg1:Event):void{
            var _local6:Number;
            var _local7:Number;
            if (siteLabuat.grabando){
                _local6 = siteLabuat.stage.mouseX;
                _local7 = siteLabuat.stage.mouseY;
            } else {
                _local6 = (dibujante.coordenadas[dibujante.punteroGrabacion].x * siteLabuat.stage.stageWidth);
                _local7 = (dibujante.coordenadas[dibujante.punteroGrabacion].y * siteLabuat.stage.stageHeight);
            };
            this.cursor.x = _local6;
            this.cursor.y = _local7;
            var _local2:Number = siteLabuat.getAngle(0, (this.stage.stageHeight / 2), _local6, _local7);
            var _local3:Number = (_local2 - this.anguloActual);
            if (_local3 > Math.PI){
                _local3 = (_local3 - (2 * Math.PI));
            };
            if (_local3 < -(Math.PI)){
                _local3 = (_local3 + (2 * Math.PI));
            };
            _local3 = (_local3 / siteLabuat.elasticidadCamara);
            this.anguloActual = (this.anguloActual + _local3);
            var _local4:Number = (this.velocidadFijaCamara * Math.cos(this.anguloActual));
            var _local5:Number = (this.velocidadFijaCamara * Math.sin(this.anguloActual));
            this.xAnterior = _local6;
            this.yAnterior = _local7;
            this.realCamarax = (this.realCamarax + ((_local4 - this.realCamarax) / siteLabuat.elasticidadCamara));
            this.realCamaray = (this.realCamaray + ((_local5 - this.realCamaray) / siteLabuat.elasticidadCamara));
            siteLabuat.camarax = Math.round(this.realCamarax);
            siteLabuat.camaray = Math.round(this.realCamaray);
            this.elDibujante.tick();
            this.elDibujante.actualizaTrazos();
            this.elDibujante.actualizaClips();
            this.dibujaFondo();
            this.stage_fondo.stage_brillo.alpha = (siteLabuat.brilloMinimo + (siteLabuat.brilloVariable * siteLabuat.elInterprete.volumenPistas(this.pistasBrillo)));
            this.stage_fondo.stage_brillo.x = (this.stage_fondo.stage_brillo.x + ((_local6 - this.stage_fondo.stage_brillo.x) / 14));
            this.stage_fondo.stage_brillo.y = (this.stage_fondo.stage_brillo.y + ((_local7 - this.stage_fondo.stage_brillo.y) / 14));
            this.stage_fondo.stage_sombraizquierda.alpha = (this.stage_fondo.stage_sombraderecha.alpha = (siteLabuat.lateralMinimo + (siteLabuat.lateralVariable * siteLabuat.elInterprete.volumenPistas(this.pistasLateral))));
        }
        private function dibujaFondo():void{
            this.transFondo.translate(-(Math.round((siteLabuat.camarax / 2))), -(Math.round((siteLabuat.camaray / 2))));
            this.transFondo.tx = (this.transFondo.tx % this.bitmapDataFondo.width);
            this.transFondo.ty = (this.transFondo.ty % this.bitmapDataFondo.height);
            this.fondo.graphics.clear();
            this.fondo.graphics.beginBitmapFill(this.bitmapDataFondo, this.transFondo, true, false);
            this.fondo.graphics.drawRect(10, 10, (this.stage.stageWidth - 20), (this.stage.stageHeight - 20));
            this.fondo.graphics.endFill();
        }
        function frame35(){
            this.stage_cargando.init();
            this.redimensiona();
        }
        private function redimensiona(_arg1:Event=null):void{
            var e = _arg1;
            try {
                this.stage_fondo.stage_sombraderecha.x = this.stage.stageWidth;
                this.stage_fondo.stage_sombraizquierda.height = (this.stage_fondo.stage_sombraderecha.height = this.stage.stageHeight);
            } catch(e:Error) {
            };
            try {
                this.stage_logo.x = (this.stage.stageWidth - 10);
                this.stage_logo.y = (this.stage.stageHeight - 10);
                this.stage_credits.y = this.stage.stageHeight;
            } catch(e:Error) {
            };
            try {
                this.stage_cargando.x = Math.round((this.stage.stageWidth / 2));
                this.stage_cargando.y = Math.round((this.stage.stageHeight / 2));
                this.stage_cargando.porcentaje.y = ((this.stage.stageHeight - this.stage_cargando.y) - 30);
            } catch(e:Error) {
            };
            try {
                this.stage_pastilla.stage_boton.x = Math.round((this.stage.stageWidth / 2));
                this.stage_pastilla.stage_boton.y = Math.round((this.stage.stageHeight / 2));
            } catch(e:Error) {
            };
            try {
                this.dibujaFondo();
            } catch(e:Error) {
            };
            try {
                this.stage_fondo.stage_brillo.x = Math.round((this.stage.stageWidth / 2));
                this.stage_fondo.stage_brillo.y = Math.round((this.stage.stageHeight / 2));
            } catch(e:Error) {
            };
            try {
                this.elDibujante.redimensiona(this.stage.stageWidth, this.stage.stageHeight);
            } catch(e:Error) {
            };
            this.stage_marco.graphics.clear();
            this.stage_marco.graphics.beginFill(0xFFFFFF, 1);
            this.stage_marco.graphics.drawRect(0, 0, this.stage.stageWidth, 10);
            this.stage_marco.graphics.drawRect(0, (this.stage.stageHeight - 10), this.stage.stageWidth, 10);
            this.stage_marco.graphics.drawRect(0, 10, 10, (this.stage.stageHeight - 20));
            this.stage_marco.graphics.drawRect((this.stage.stageWidth - 10), 10, 10, (this.stage.stageHeight - 20));
        }
        function frame64(){
            this.stop();
        }
        private function cancionCargando(_arg1:ProgressEvent):void{
            var e:* = _arg1;
            var p:* = (e.bytesLoaded / e.bytesTotal);
            try {
                this.stage_cargando.setPercent(Math.round((75 * p)));
            } catch(e:Error) {
            };
        }
        private function XMLCargado(_arg1:Event):void{
            siteLabuat.setup = new XML(_arg1.target.data);
            this.pistasCamara = new Array();
            var _local2:Array = siteLabuat.setup.sincronizacion.camara.toString().split(",");
            var _local3:int;
            while (_local3 < _local2.length) {
                this.pistasCamara.push(int(_local2[_local3]));
                _local3++;
            };
            this.pistasBrillo = new Array();
            _local2 = siteLabuat.setup.sincronizacion.brillo.toString().split(",");
            _local3 = 0;
            while (_local3 < _local2.length) {
                this.pistasBrillo.push(int(_local2[_local3]));
                _local3++;
            };
            this.pistasLateral = new Array();
            _local2 = siteLabuat.setup.sincronizacion.lateral.toString().split(",");
            _local3 = 0;
            while (_local3 < _local2.length) {
                this.pistasLateral.push(int(_local2[_local3]));
                _local3++;
            };
            var _local4:Loader = new Loader();
            _local4.load(new URLRequest(siteLabuat.setup.media.gfx.fondo.toString()));
            _local4.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, this.backgroundLoadProgress);
            _local4.contentLoaderInfo.addEventListener(Event.COMPLETE, this.backgroundLoadComplete);
        }
        public function toggleFullScreen(_arg1:MouseEvent):void{
            navigateToURL(new URLRequest("http://utf-8.tk"), "_blank");
        }
        private function iniSite():void{
            siteLabuat.elDisparadorXML = new interpreteXML(siteLabuat.setup.eventos.evento);
            this.elDibujante.inicializa((this.stage.stageWidth / 2), (this.stage.stageHeight / 2));
            this.elDibujante.redimensiona(this.stage.stageWidth, this.stage.stageHeight);
            this.playable();
        }
        private function soundCompleteHandler(_arg1:Event):void{
            var e:* = _arg1;
            try {
                this.para();
            } catch(e:Error) {
            };
            this.gotoAndPlay("Termina");
            this.stage_credits.despliega();
        }
        private function dibujanteCargando(_arg1:ProgressEvent):void{
            var e:* = _arg1;
            var p:* = (e.bytesLoaded / e.bytesTotal);
            try {
                this.stage_cargando.setPercent((75 + Math.round((24 * p))));
            } catch(e:Error) {
            };
        }
        private function cancionCargada(_arg1:Event):void{
            this.elDibujante = new dibujante(this.stage_canvas);
            this.elDibujante.addEventListener(ProgressEvent.PROGRESS, this.dibujanteCargando);
            this.elDibujante.addEventListener(Event.COMPLETE, this.dibujanteCargado);
        }
        private function XMLPersoCargado(_arg1:Event):void{
            var _local4:Array;
            var _local5:int;
            var _local6:Array;
            var _local2:* = new XML(_arg1.target.data);
            var _local3:String = _local2.secuencia.toString();
            if (((_local3) && ((_local3.length > 0)))){
                _local4 = _local3.split("|");
                siteLabuat.grabando = false;
                dibujante.coordenadas = new Array();
                _local5 = 0;
                while (_local5 < _local4.length) {
                    _local6 = _local4[_local5].split(",");
                    dibujante.coordenadas[dibujante.coordenadas.length] = {x:(parseFloat(_local6[0]) / 2000), y:(parseFloat(_local6[1]) / 1000), tiempo:(parseFloat(_local6[2]) * 10)};
                    _local5++;
                };
            };
            this.stage_cargando.addEventListener(Event.COMPLETE, this.cargandoCompletado);
            this.stage_cargando.setPercent(100);
        }
        public function para():void{
            Mouse.show();
            this.timerCamara.stop();
            this.removeEventListener(Event.ENTER_FRAME, this.tick);
            this.elReproductor.para();
            this.elDibujante.para();
            siteLabuat.elInterprete.para();
            siteLabuat.sigueMouse = false;
            siteLabuat.elDisparadorXML.para();
            if (siteLabuat.grabando){
                this.removeChild(this.cursor);
            };
        }
        function frame1(){
            Mouse.hide();
            this.stop();
        }
        function frame4(){
            this.redimensiona();
        }
        private function go(_arg1:Event):void{
            var _local2:MovieClip = (_arg1.target as MovieClip);
            _local2.buttonMode = false;
            _local2.removeEventListener(MouseEvent.CLICK, this.go);
            siteLabuat.elInterprete.reproduce(0);
            siteLabuat.elInterprete.addEventListener(Event.SOUND_COMPLETE, this.soundCompleteHandler);
            this.elReproductor.addEventListener(Event.COMPLETE, this.soundCompleteHandler);
            this.velocidadFijaCamara = 50;
            this.empieza();
            var _local3:MovieClip = this.elDibujante.nuevoClip("splatter4", (this.stage.stageWidth / 2), (this.stage.stageHeight / 2));
            _local3.scaleX = (_local3.scaleY = 0.3);
            this.gotoAndPlay("Reproduce");
            if (siteLabuat.grabando){
                this.elReproductor.gotoAndStop(3);
            } else {
                this.elReproductor.gotoAndStop(1);
            };
        }
        private function dibujanteCargado(_arg1:Event):void{
            var _local4:URLRequest;
            var _local5:URLLoader;
            var _local2:Object = LoaderInfo(this.root.loaderInfo).parameters;
            var _local3:Number = Number(_local2["id"]);
            if (((_local3) && (!(isNaN(_local3))))){
                _local4 = new URLRequest(("getinfo.php?id=" + _local3));
                _local5 = new URLLoader(_local4);
                _local5.load(_local4);
                _local5.addEventListener(Event.COMPLETE, this.XMLPersoCargado, false, 0, true);
            } else {
                this.stage_cargando.addEventListener(Event.COMPLETE, this.cargandoCompletado);
                this.stage_cargando.setPercent(100);
            };
        }
        private function cargandoCompletado(_arg1:Event):void{
            this.stage.quality = "high";
            this.stage_cargando.removeEventListener(Event.COMPLETE, this.cargandoCompletado);
            this.iniSite();
        }
        function frame131(){
            this.stop();
        }

        public static function getAngle(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number):Number{
            var _local5:Number = Math.atan2((_arg4 - _arg2), (_arg3 - _arg1));
            return (_local5);
        }

    }
}//package 

  代码写到现在,终于明白代码是要规范的。一直不会用辅助程序写,今天在主程写了1600行代码,写的头都大了。果然领悟其缺点。

posted @ 2012-10-31 20:12  小糊涂仙儿  阅读(340)  评论(0)    收藏  举报