Skip to main content
Inspiring
February 11, 2011
Answered

loader class: multiple movies: mouse click to navigate

  • February 11, 2011
  • 2 replies
  • 814 views

I need to use this for two projects. One where a game will be played, then the next game loads when you click on end etc... Another where it is just a presentation. I supppose the main movie would have a navigation bar - but wouldn't that disappear as I load the next movie in.

It's easy to use the loader class but when I want to use various clips I get problems.

ie: Do I have to use a Container movieclip where all movies are loaded into or does each new movieclip create a new loader instance to be able to load the next movie. This is not for a website.

This topic has been closed for replies.
Correct answer moccamaximum

Did sth. similar recently on a job. Maybe that helps:

//LoadingGames

var games_array:Array=["game1.swf","game2.swf","presentation.swf"];
var gamesIndex:uint=0;

//In the library

var gameloadingbar:LoadingBar = new LoadingBar();

function loadGame(e:MouseEvent) {
    addChild(gameloadingbar);
    //center(gameloadingbar);
    gameLoader = new Loader();
    gameLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
    gameLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
    var gameURL:String=games_array[gamesIndex];
    gameLoader.load(new URLRequest(gameURL));

    //preparing for next Content
    gamesIndex++;
}

function loop(e:ProgressEvent):void {
    var perc:Number=e.bytesLoaded/e.bytesTotal;
    perc=Math.ceil(perc*100);
    trace(perc);
    trace(Math.floor(perc/7)+1);
    Object(this).gameloadingbar.txt.text=perc;
}

function done(e:Event):void {
    removeChild(gameloadingbar);
    //gameloadingbar = null;
    addChild(gameLoader);
}

2 replies

Inspiring
February 18, 2011

Thanks

moccamaximumCorrect answer
Inspiring
February 11, 2011

Did sth. similar recently on a job. Maybe that helps:

//LoadingGames

var games_array:Array=["game1.swf","game2.swf","presentation.swf"];
var gamesIndex:uint=0;

//In the library

var gameloadingbar:LoadingBar = new LoadingBar();

function loadGame(e:MouseEvent) {
    addChild(gameloadingbar);
    //center(gameloadingbar);
    gameLoader = new Loader();
    gameLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
    gameLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
    var gameURL:String=games_array[gamesIndex];
    gameLoader.load(new URLRequest(gameURL));

    //preparing for next Content
    gamesIndex++;
}

function loop(e:ProgressEvent):void {
    var perc:Number=e.bytesLoaded/e.bytesTotal;
    perc=Math.ceil(perc*100);
    trace(perc);
    trace(Math.floor(perc/7)+1);
    Object(this).gameloadingbar.txt.text=perc;
}

function done(e:Event):void {
    removeChild(gameloadingbar);
    //gameloadingbar = null;
    addChild(gameLoader);
}

Inspiring
February 13, 2011

Hi.

I've actually got this code - but it's great to get it confirmed. An xml config file could develop the game array further. ie: It's more flexible - just need to change xml and not open fla again to republish.

However, my question was how you got to the next game. ie: You finish game 1 - how to you get to game two. What code would you write - and what event is used - or is there some sort of event dispatch code. (I must have phrased my original request badly)

What I mean also, is how is it loaded. Do you write loader code again or what?

Also, I read that you could use multiple loaders - ie: If you are playing one game, you have a loader in the background loading the second game. If you need code I could send a link.

Cheers

Inspiring
February 13, 2011

Also, I read that you have to remove all references to a listener otherwise it continues even though you used removeChild(gameloadingbar);

You need to use remove listener. Also, I think they set something to null. Maybe you don't need all this but I think it's best practise in the long run especially for mobile dev.