A Flash Developer Resource Site

Results 1 to 20 of 24

Thread: Preloader effect

Threaded View

  1. #21
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    wrap an on(press) action around it..

    like this:

    Code:
    on (press) {
    	var container = this.createEmptyMovieClip("container", 1);
    	container.loadMovie("external.jpg");
    	var bgColor = 0xEEEEEE;
    	var barColor = 0x996666;
    	var percentColor = 0xCCCC99;
    	// create the necessary movieclips
    	// create prealoader clip
    	var _preLoad = _root.createEmptyMovieClip("_preLoad", 200);
    	// position the loader center stage
    	_preLoad._x = Math.round((Stage.width / 2) - 100);
    	_preLoad._y = Math.round((Stage.height / 2 - 10));
    	// create loading bar  clip
    	var bg = _preLoad.createEmptyMovieClip("bg", 1);
    	// draw the load bar background
    	bg.lineStyle(0, barColor, 100);
    	bg.beginFill(bgColor, 75);
    	bg.lineTo(200, 0);
    	bg.lineTo(200, 13);
    	bg.lineTo(0, 13);
    	bg.lineTo(0, 0);
    	bg.endFill();
    	// create a Text Format object
    	var tf = new TextFormat();
    	tf.font = "Verdana";
    	tf.align = "left";
    	tf.size = 10;
    	tf.color = percentColor;
    	_root.container.stop();
    	_preLoad.onEnterFrame = function() {
    		var loadBar = bg.createEmptyMovieClip("loadBar", 5);
    		// create the textfield
    		bg.createTextField("display_txt", 6, (this.bg._width / 2 - 50), -2, 0, 0);
    		if (_root.container.getBytesLoaded() > 0) {
    			var percent = Math.round((100 / _root.container.getBytesTotal()) * _root.container.getBytesLoaded());
    		} else {
    			var percent = 0;
    		}
    		bg.display_txt.autoSize = true;
    		bg.display_txt.text = "Loading... " + percent + "%";
    		bg.display_txt.setTextFormat(tf);
    		// progress bar
    		bg.loadBar.beginFill(barColor, 100);
    		bg.loadBar.lineTo(percent * 2, 0);
    		bg.loadBar.lineTo(percent * 2, 13);
    		bg.loadBar.lineTo(0, 13);
    		bg.loadBar.lineTo(0, 0);
    		bg.loadBar.endFill();
    		if (percent >= 100) {
    			_preLoad.removeMovieClip();
    			delete this.onEnterFrame;
    			bg.display_txt.text = "";
    		}
    	};
    	stop();
    }

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