A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Preloader code not working - please hope me!

  1. #1
    Junior Member
    Join Date
    May 2006
    Location
    Cleveland, Ohio
    Posts
    11

    Preloader code not working - please hope me!

    Please help! I don't understand what I'm doing wrong. Here is my abbreviated code.

    Code:
    package {
        import flash.display.*;
        import flash.text.TextField;
        import flash.events.*;
        
        public class Main extends MovieClip {
    
            public var loadText:TextField = new TextField();
            
            public function Main() {
                stop();
                
                loadText.height = 20;
                loadText.width = 50;
                loadText.x = 450;
                loadText.y = 250;
                loadText.border = false;
                loadText.background = false;
                loadText.textColor = 0x000000;
                loadText.selectable = false;
                loadText.text = "0%";
                addChild(loadText);
                
                this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, checkProgress);
                this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
            
            }
            
            private function checkProgress(e:ProgressEvent):void {
    
                var total:Number = e.bytesTotal;
                var loaded:Number = e.bytesLoaded;
    
                loadText.text = Math.floor((loaded/total)*100)+ "%";
    
                if (total == loaded){
                    removeChild(loadText);
                    this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, checkProgress);
                }
            }
            private function onComplete(e:Event):void {
                this.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
                init();
            }
    }
    When I test this and do a simulated download, I get a white screen for a few seconds and then the init() function fires and the movie starts. What am I doing wrong?

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    15
    that is what it is suppose to do.

  3. #3
    Junior Member
    Join Date
    May 2006
    Location
    Cleveland, Ohio
    Posts
    11
    But the document background color is actually red, and the loader text is not showing. I was hoping it would show an increasing percentage load in the text field I added to the stage. I don't see it.

  4. #4
    Junior Member
    Join Date
    Jan 2009
    Posts
    15
    i tested your code just added the init function to tell it to play not sure what you have in your ... your posted code above was missing a } at the very end... i saw the percentage text in mine.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center