对象加载问题

时间:2015-01-13 16:30:27

标签: actionscript-3 flash-cs5

我正在开发一个由多个不同对象组成的应用程序。一切似乎都很好,但是,当我在Web服务器上播放时,我注意到从外部源加载的图形和资产需要一些时间来加载我不太确定发生了什么我希望有人可能提供一些见解。例如,有时图形资产根本不会加载,但音频似乎正在加载。以下是我的图片加载类的示例:

GFXReg.as

package {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.text.TextField;

    public class GFXReg extends Sprite {
        private var mc: MovieClip = new MovieClip();
        private var loader: Loader = new Loader();
        private var setW: Number;
        public var setH: Number;
        public var theH: Number;
        private var bool: Boolean = false;

        public function GFXReg(setSize: Boolean, W: Number, H: Number) {
            bool = setSize;
            if (bool) {
                setW = W;
                setH = H;
            }
        }

        private function loadData(e: Event) {
            if(loader.contentLoaderInfo.bytesLoaded == loader.contentLoaderInfo.bytesTotal){
                addChild(loader);   
                }else{
                        var text:TextField = new TextField();
                        text.text = "Loading..."
                        addChild(text);
                    }

            if (bool) {
                loader.width = setW;
                loader.height = setH;
            }
        }
        public function theData(file: String): void {
            loader.load(new URLRequest(file));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadData);
        }
        public function getBytes(str:String):int{
            var num:int = 0;
                switch(str){
                        case "loaded":
                        num = loader.contentLoaderInfo.bytesLoaded;
                        break;
                        case "total":
                        num = loader.contentLoaderInfo.bytesTotal;
                        break;
                    }
                    return num;
            }
        public function removeData():void{
                loader.unloadAndStop(false);
                trace("unload?");
            }
        private function unloadData(e:Event):void{

            }
    }
}

Main.as Sections (在提示时加载所有相应的部分):

public function Main() {
            xmlLoader = new XMLReg("config.xml", processXML);
        }
        private function processXML(e: Event): void {
            theXML = new XML(e.target.data);
            dir = theXML.MASTER.@DIRECTORY;
            //BACKGROUND
            bgGFX.theData(dir + theXML.MAINBG.@IMG);
            //INITIALIZE
            add(bgGFX,intro);

                              //INTRO WAS INSTANTIATED IN THE BEGINNING OF THIS CLASS
            intro.start();
                              /*start method adds objects to stage, to test as a solution*/

            addChildAt(header, numChildren);
            //...

同样在我的 Main.as 类中,我有一个私有方法转换,在前面的部分完成后加载到适当的部分,这些资产通常需要几秒钟才能加载我已经注意到了在Web服务器上工作时。

        private function transition(e: Event): void {
//If intro is on the stage instantiate a new QuestionAnswer Object
            if (intro.stage) {
                header.enableMenu(true);
                qa = new QuestAnswer(feedBool,nameCounter,nameVar);
                qa.addEventListener("unload", transition);
                qa.addEventListener("addFeed", setFeedFalse);
                qa.addEventListener("addFeedTrue", setFeedTrue);
                qa.addEventListener("enableHelp",enableHelp);
                qa.addEventListener("getName",getName);
                addChildAt(qa, numChildren-1);
                remove(intro);
            } else if (qa.stage) {
//If QuestionAnswer is on the Stage instantiate a new Results Object
                header.enableMenu(true);
                header.enableHelp(false);
                results = new Results(qa.resultBundle());
                results.addEventListener("unload", transition);
                results.addEventListener("addFeed", setFeedFalse);
                results.addEventListener("addFeedTrue", setFeedTrue);
                results.addEventListener("setName",setName);
                addChildAt(results, numChildren-1);
                remove(qa);
            } else if (results.stage) {
//If Results is on the stage loop back and instantiate a new QuestionAnswer Object
                header.enableMenu(true);
                header.enableHelp(false);
                intro.enableAsset(true);
                qa = new QuestAnswer(feedBool,nameCounter,nameVar);
                qa.addEventListener("unload", transition);
                qa.addEventListener("addFeed", setFeedFalse);
                qa.addEventListener("addFeedTrue", setFeedTrue);
                addChildAt(qa, numChildren-1);
                trackAsset = true;
                remove(results);
            }
        }

0 个答案:

没有答案