PDA

View Full Version : After the preloader is loaded goto frame/label



chrisdegrote
October 3rd, 2009, 10:45 AM
Hey people,

I've bought a very simple AS3 preloader but the default code requests an external swf thru a loader event.

What I would like to achieve is when the content is loaded it goes to a frame/label on my stage.

This is the code now



// create a new Loader
var loader:Loader = new Loader();

// add the progress event to the loader that calls the "loading" function
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, loading);

// add the complete event to the loader so that when it finishes loading
// calls the "loadContent" function
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadContent);

// add the loader on the stage
addChild(loader);

// set the url to be loaded inside the loader once the "loadContent"
// function is called
loader.load(new URLRequest("main.swf"));

// this function checks the loading progress
function loading(event:ProgressEvent):void
{

// this variable is equal to the loaded bytes divided by the total bytes
// returns a number between 0 and 1
var loaded:Number = event.bytesLoaded / event.bytesTotal;

// set the progress bar x scale to be equal to the "loaded" variable
progress_bar.bar.scaleX = loaded;

// set the dynamic text field text "perc_txt" to be equal to the
// "loaded" variable multiplied by 100 -> returns a round number
// between 0 and 100
loading_info.perc_txt.text = Math.round(loaded*100).toString()+"%";
}

// this function is called when the loaded bytes are equal to the total bytes
function loadContent(event:Event):void
{
// remove the loading_info movie clip from the stage
removeChild(loading_info);

// set the dynamic text field perc_txt value to null
loading_info.perc_txt = null;

}


Can somebody help me to change the function.

Thank you very for your time

Scott64
October 3rd, 2009, 10:50 AM
In the loadContent function, add a line that says gotoAndStop(frameNumber) or gotoAndStop("frameLabel") (or use gotoAndPlay())