AS2: simple pre-loader

6 4 17th 2010 § 0 comments

…because it just won’t die, here is some more AS2 for you.

stop();
function playClip(){gotoAndPlay(2)};
function newPrct()
{
	var prct:Number = Math.floor( ( this.getBytesLoaded() / this.getBytesTotal() ) * 100 );
	( prct == 100 )?playClip():setTimeout( function(){newPrct();},250 );
}
newPrct();

I go into more detail after the jump.

// stop the movie before it starts.
stop();

// simple go to this frame and play function
function playClip(){gotoAndPlay(2)};   

// set the variable for PERCENT
var prct:Number = 0;

// the function to check the percentage loaded.
function newPrct()
{
	// find the PERCENT by dividing loaded by total bytes.
	prct = Math.floor( ( this.getBytesLoaded() / this.getBytesTotal() ) * 100 );

	// trace out the PERCENT
	trace( "\t"+prct );

/*
	simple IF / ELSE -
	if PERCENT is 100, play the "playClip" function
	or run this function again in a quarter of a second.
*/
	( prct == 100 )?playClip():setTimeout( function(){newPrct();},250 );
}

// start it off!
newPrct();

Tagged , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What's this?

You are currently reading AS2: simple pre-loader at DrPunchBlog.

meta

  •  

    June 2010
    M T W T F S S
    « May   Jul »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
  • Archives

  • The Uber-Mannerist ...
    By Van Arno
  • RSS mtr.me

    • ‘Up In The Air’ Producer Launches The Allegiance Shingle With IM Global-Funded ‘Money Monster’
      EXCLUSIVE: Daniel Dubiecki has launched The Allegiance Theater, a association designed to emanate a breakwater where talent and financiers can induce film and TV projects. The association gets off a belligerent with a privately-backed beyond and growth account to beget character-driven, commercially appealing stories, pronounced Dubiecki. As Jason Reitman’s […]
    • New Oils
      James and Esao both published oil paintings to their blogs recently, James’s work on tip is titled, “Pauline Prieto“, and Esao’s investigate underneath it is substantially eleven or thirteen years aged now from art propagandize and he writes about because it is called “Grumpy Study”. Article source: http://meathaus.com/2012/02/06/new-oils/ […]
    • Video Game Character Facebook Profiles
      This is a array of cinema from a Facebook profiles of video diversion characters. Obviously they’re fake, that we wish we would’ve famous before spending a half hour perplexing to find and crony Nathan Drake and Solid Snake. OMG, how cold would it be to know those dual guys in genuine life? “Wow,GW — man-crush […]
  • Translator