A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [MX] Preloader Path Problem for Loaded Movie

  1. #1
    Junior Member
    Join Date
    Oct 2003
    Posts
    11

    [MX] Preloader Path Problem for Loaded Movie

    I have created two flash files. One contains the main content of my flash website(design2.swf). The other(finaldesignsite06.fla) contains the code to load design2.swf:
    Code:
    (loadMovieNum ("design2.swf", 1);
    stop ();
    The first purpose of loading one movie into the other is a workaround to solve some gif distortion problems. The second purpose is to try to solve some preloader problems I am having(which I have not completely solved yet)(yes, I have unchecked export on first frame)

    Here is what I need help with: I would like to have the preloader that is within finaldesignsite06.fla show how much of design2.swf has loaded.


    Here is the code I am using right now:
    Code:
    //this is in the first keyframe
    bytes_loaded = Math.round(_level1.getBytesLoaded());
    bytes_total = Math.round(_level1.getBytesTotal());
    getPercent = bytes_loaded/bytes_total;
    this.loadBar._width = getPercent*300;
    this.loadText = Math.round(getPercent*100)+"%";
    if (bytes_loaded == bytes_total) {
    	this.gotoAndPlay(4);
    }
    Code:
    //this is in the second keyframe
    this.gotoAndPlay(1);
    Does anybody have any suggestions for how to make this work?
    Thank you.

  2. #2
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    This will do it all on the fly.... (in both examples, you'll need to upload the files to your server to test them...as you can't test preloaders locally)
    Code:
    loadMovieNum("design2.swf", 1);
    
    this.createEmptyMovieClip("progressBar_mc", 2);
    progressBar_mc.createEmptyMovieClip("bar_mc", 3);
    progressBar_mc.createEmptyMovieClip("stroke_mc", 4);
    
    with (progressBar_mc.stroke_mc) {
      lineStyle(1, 0xFFFFFF);
      moveTo(0, 0);
      lineTo(100, 0);
      lineTo(100, 10);
      lineTo(0, 10);
      lineTo(0, 0);
    }
    with (progressBar_mc.bar_mc) {
      beginFill(0xCCCCCC, 100);
      moveTo(0, 0);
      lineTo(100, 0);
      lineTo(100, 10);
      lineTo(0, 10);
      lineTo(0, 0);
      endFill();
      _xscale = 0;
    }
    
    progressBar_mc._x = 20;
    progressBar_mc._y = 20;
    
    progressBar_mc.onEnterFrame = function () {
    	loaded = _level1.getBytesLoaded()/1000;
    	total = _level1.getBytesTotal()/1000;
    	percent = Math.ceil(loaded/total)*100;
    	this.bar_mc._xscale = percent;
    	if (percent == 100) {
    		delete this.onEnterFrame;
    		this.removeMovieClip();
    	}
    };
    or this will work as well. create your preloader mc with the first frame empty... just put a stop() on it. Then on the 2nd frame, create a loadBar movieclip with the instance name loadBar and a dynamic textfield with the instance name display_txt. Then place this code on the 2nd frame:
    Code:
    this.onEnterFrame = function(){
        percent = (_level1.getBytesLoaded()/_level1.getBytesTotal())*100;
    
    	if(!isNaN(percent)){
    		if (percent == 0) {
    			display_txt.text = "";
    		} else {
    			display_txt.text = Math.ceil(percent) + "% Loaded";
    		}
    		loadBar._xscale = percent;
    		_level1.stop();
    	}
        if(percent == 100){
    		this.gotoAndStop(1);
    		delete this.onEnterFrame;
    		_level1.play();
    		}
    }
    stop();
    
    
    // then on your main timeline, you'd load the movie and call the preloader like this:
    
    loadMovieNum("design2.swf", 1);
    preloader.gotoAndStop(2);
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

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