zoukankan      html  css  js  c++  java
  • actionscript项目中自加载preloader实现

    package
    {
     import flash.display.DisplayObject;
     import flash.display.MovieClip;
     import flash.display.Sprite;
     import flash.display.StageAlign;
     import flash.display.StageScaleMode;
     import flash.events.Event;
     import flash.events.IOErrorEvent;
     import flash.events.ProgressEvent;
     import flash.utils.getDefinitionByName;
     
     
     public class Preloader extends MovieClip
     {
      private var bar:Sprite;
      
      public function Preloader()
      {
       if (stage)
       {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
       }
       addEventListener(Event.ENTER_FRAME, checkFrame);
       loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
       loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
       
       // TODO show loader
       bar = new Sprite();
       bar.graphics.lineStyle(1, 0x4444ff, 1, true);
       bar.graphics.drawRect(0, 0, 100, 6);
       bar.x = stage.stageWidth / 2 - bar.width / 2;
       bar.y = stage.stageHeight / 2 - bar.height / 2;
       addChild(bar);
      }
      
      private function ioError(e:IOErrorEvent):void
      {
       trace(e.text);
      }
      
      private function progress(e:ProgressEvent):void
      {
       // TODO update loader
       bar.graphics.lineStyle(0, 0, 0);
       bar.graphics.beginFill(0x8888ff);
       bar.graphics.drawRect(1, 1, (e.bytesLoaded / e.bytesTotal) * 98, 4);
       bar.graphics.endFill();
       trace("loading:" + (e.bytesLoaded / e.bytesTotal) * 100);
       trace(e.bytesTotal);
      }
      
      private function checkFrame(e:Event):void
      {
       if (currentFrame == totalFrames)
       {
        stop();
        loadingFinished();
       }
      }
      
      private function loadingFinished():void
      {
       removeEventListener(Event.ENTER_FRAME, checkFrame);
       loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
       loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
       
       // TODO hide loader
       removeChild(bar);
       bar = null;
       
       startup();
      }
      
      private function startup():void
      {
       var mainClass:Class = getDefinitionByName("Main") as Class;
       stage.addChild(new mainClass() as DisplayObject);

       parent.removeChild(this);
      }
     
     }

    }

    再来看看主程序怎么用的:

    package
    {            
        import flash.display.Sprite;            
        import flash.events.Event;            
                                 
        [Frame(factoryClass="Preloader")]            
        public class Main extends Sprite            
        {            
            public function Main()            
            {            
                super();            
                this.addEventListener(Event.ADDED_TO_STAGE, onadded);            
            }            
                                 
            protected function onadded(event:Event):void
            {            
                trace("真实内容加载到舞台");            
            }            
        }            
    }
  • 相关阅读:
    css实现梯形
    CSS3自定义滚动条样式 -webkit-scrollbar
    MySQL-5.6.13免安装版配置方法
    CSS边框长度控制
    The Shapes of CSS(css的形状)
    CSS制作图形速查表
    使用onclick跳转到其他页面/跳转到指定url
    TCP/IP协议
    jQuery实现全选、反选和不选功能
    checkbox在vue中的用法小结
  • 原文地址:https://www.cnblogs.com/autumndawn/p/3447575.html
Copyright © 2011-2022 走看看