问题preloading与出口的框架2 [英] Problems preloading with export on frame 2

查看:129
本文介绍了问题preloading与出口的框架2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉标题,我不完全知道如何用几句话解释这一点。

Sorry about the title, I'm not exactly sure how to explain this with a few words.

我已经通过谷歌搜索看了一下,发现,人们发现它easlier使用preloader当框架2出口​​类时。我目前使用具有与preloader帧1的常用方法,帧2与资产保持器和本体的游戏,帧3具有止挡();行动。这是我跟得到一个工作preloader的 AS玩家

I've looked through google searches and found that people find it easlier when exporting classes in frame 2 when using a preloader. I'm currently using the usual method of having frame 1 with the preloader, frame 2 with the asset holder and the bulk of the game, frame 3 has the stop(); action. This is the tutorial I followed to get a working preloader AS Gamer.

几个小时寻找,我只发现后提到和人民revalations在框架2 使用代替了传统的资产持有人的的出口,但没有例子或教程。

After many hours of searching I've only found mentions and revalations of people using export on frame 2 instead of the traditional asset holder, but no examples or tutorials.

有哪位知道在哪里可以找到例如code教程我引用得到帧2 preloader一个出口?

Does any know where I can find a tutorial with example code I reference to get a export on frame 2 preloader?

推荐答案

我一直写在preloaders这个问题的完整的教程,但我仍然在中间让我的新网站推出......在那之前,这里有hightlights:

I've been meaning to write a complete tutorial on the subject of preloaders, but I'm still in the middle of getting my new site launched... until then, here are the hightlights:

两个部件也都将需要 -

Two parts are going to be required -

在JavaScript端之一:发送Flash变量到preloader,和flash对象嵌入到HTML结构。我爱SWFObject的为它的简单性和bulletproofness。

one on the javascript side: sending flashvars into the preloader, and embedding the flash object into the html structure. I love swfobject for its simplicity and its bulletproofness.

HTML:

<html>
  <head>
  <script type="text/javascript" src="/javascript/swfobject/swfobject.js"></script>
  <script type="text/javascript" src="/javascript/logic.js"></script>
  </head>
  <body>
    <div id="flashContainer">content for when swfobject fails</div>
  </body>
</html>

logic.js:

logic.js:

var _flashvars  =
    {
        filePath    : "/flash/swf/yourcontent.swf",
        FR          : "60",
        verbose     : "false",
        SW          : "760",
        SH          : "550"
    };

var _params     =
    {
        quality     : 'high',
        menu        : 'false',
        base        : '/flash/swf/'
    };

var _attr =
    {
        id          : "flashContainer"
    };

function embedSWF()
    {
        swfobject.embedSWF(
                "/flash/preLoader.swf",
                "flashContainer",
                "760",
                "550",
                "9.0.0",
                "/javascript/swfobject/expressInstall.swf",
                _flashvars,
                _params,
                _attr 
                );
        return;
    }

//onload event
embedSWF()

在闪光灯方面,我们有preloader FLA(或无论你正在构建它)。它的目的地的内容无关的,因为我重新使用它为我所有的preloading。你可以节省一些时间通过硬编码的Flash变量,我spose。不管怎么说,我有两个班 -

On the flash side, we have the preloader fla (or however you're building it). Its purposefully "content-agnostic" because I reuse it for all my preloading. You could save some time by hardcoding in the flash vars, i spose. Anyway, I've got two classes -

Main.as - 这在运行时拉入Flash变量,启动负载,并且然后响应于装载进展,最后加入加载的内容成显示列表。

Main.as - which pulls in the flashvars at runtime, initiates the load, and then responds to the loading progress, finally adding the loaded content into the display list.

preloader.as - 这确实所有繁重

Preloader.as - which does all the heavy lifting.

请注意,这些都是直接从我的项目部分类拉,我也只包括最基本的(你必须完成了code和裁缝根据需要)。

Note these are partial classes pulled directly from my project, and I've included only the bare essentials (you'll have to finish out the code and tailor as needed).

另请注意,这是一个很多方法可以做到这一点;)

Note also that this is one of many ways to do this ;)

Main.as:

 package {

            public class Main extends MovieClip 
            {
                private var _loadParams         :Object;
                private var _filePath           :String;
                private var _frameRate          :uint;
                private var _stageH             :Number;
                private var _stageW             :Number;
                private var _verbose            :Boolean;

                public function Main():void 
                {
                    super();

                    if (stage)
                    {
                        init();
                    }
                    else 
                    {
                        this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
                    }
                }

                /**
                 * once preloader is onstage, create param object. 
                 * assign vars from param object
                 * 
                 * stage height / stage width: 
                 * some files may have SH and SW defined, if they are, used them as 
                 * stage dimensions. If they are not, default to current stageHeight,Width
                 * 
                 * @param   e
                 */
                private function init(e:Event = null):void 
                {
                    this.removeEventListener(Event.ADDED_TO_STAGE, init);

                    stage.align = StageAlign.TOP_LEFT;
                    stage.scaleMode = StageScaleMode.NO_SCALE;

                    _loadParams = new Object();
                    _loadParams = LoaderInfo(stage.loaderInfo).parameters;

                    _filePath   = String(   parseParam( "filePath", "undefined.swf"             ) );
                    _frameRate  = uint(     parseParam( "FR",       "24"                        ) );

                    _stageH         = Number(   parseParam( "SH",       String(stage.stageHeight)   ) );
                    _stageW         = Number(   parseParam( "SW",       String(stage.stageWidth)    ) );

                    ( String( parseParam( "verbose", "true" )) == "true")?_verbose = true : _verbose = false;

                    initiateLoader();
                }

                private function parseParam(name:String, defaultValue:String):String
                {
                    if (_loadParams.hasOwnProperty(name) && _loadParams[name] != "" && _loadParams[name] != "undefined") 
                    {
                        return _loadParams[name];
                    }
                    else
                    {   
                        return defaultValue;
                    }
                }

                private function initiateLoader():void
                {
                    _loader = new PreLoader(_filePath, _verbose);
                    _loader.addEventListener("displayObjectLoaded", onLoadComplete, false, 0, true);
                    this.addEventListener(Event.ENTER_FRAME,    setLoadPercentage,  false,  0,  true); 
                }


                /**
                * respond to load graphically
                */
                private function setLoadPercentage(e:Event):void 
                {
                    _loadPercentage = Math.round((_loader.progressNumberArray[0] /_loader.progressNumberArray[1])*100);
                    if (_verbose)
                    {
                    _txt.text = String(_loadPercentage) + "% Loaded";
                    }
                }

                /**
                 * finally, add the loader object into the display list.
                 */
                private function onLoadComplete(evt:Event):void 
                {
                    _loader.removeEventListener("displayObjectLoaded", onLoadComplete);
                    this.removeEventListener(Event.ENTER_FRAME, setLoadPercentage);

                    this.addChild(_loader);         
                }

preloader.as

Preloader.as

package {

    import flash.display.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import flash.text.TextField;

    public class PreLoader extends Sprite {

        private var _loader             : Loader;
        private var _loaderInfo         : LoaderInfo;
        private var _verbose            : Boolean = false;
        private var _loadProgressString : String = "";
        private var _bytesLoaded        : Number = 0;
        private var _bytesTotal         : Number = 0;

        public function PreLoader(path:String, verbose:Boolean) 
        {
            _verbose    = verbose;

            _loader     = new Loader();
            _loaderInfo = _loader.contentLoaderInfo;

                // there are several other events to listen for and respond to
            _loaderInfo.addEventListener(ProgressEvent.PROGRESS,    onProgress, false, 0, true);
            _loaderInfo.addEventListener(Event.COMPLETE,            onComplete, false, 0, true);

            try 
            {
                _loader.load(new URLRequest(path));

            } 
                catch (evt:Error) 
            {
                _loader.unload();

                var errMsg:TextField = new TextField();
                with (errMsg) {
                    width       = 300;
                    text        = "Unable to load content:\n" + evt.toString();
                }
                addChild(errMsg);
                dispatchEvent(new Event("displayObjectLoaded"));
            }
        }

            private function onProgress(evt:ProgressEvent):void 
        {
            var loadPercent:int = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100);
            _bytesLoaded        = evt.bytesLoaded;
            _bytesTotal         = evt.bytesTotal;
            _loadProgressString = (loadPercent + " % loaded: " + _bytesLoaded + " bytes of " + _bytesTotal + " total bytes");
            if (_verbose) 
                {
                trace(_loadProgressString);
            }
        }


        private function onComplete(evt:Event):void 
        {
            _loaderInfo.removeEventListener(Event.COMPLETE,         onComplete);
            _loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);


            addChild(_loader);
            dispatchEvent(new Event("displayObjectLoaded"));
        }

            /**
             * getter for load details
             */
        public function get progressNumberArray():Array 
        {
            return [_bytesLoaded,_bytesTotal];
        }

希望这有助于让你开始。让我知道,如果你有任何问题。

Hopefully that helps get you started. Let me know if you have any questions.

干杯!

这篇关于问题preloading与出口的框架2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆