Skip to main content
Inspiring
February 12, 2013
Answered

Hi. Really need help.

  • February 12, 2013
  • 1 reply
  • 570 views

I am trying to make a game right now. When you successfully finished the current level it should unlock the next level.  I've been googling since this morning and tried using SharedObject but it won't solve my problem. I really need help please! Can someone please give me an idea on how I can do this? >.< Thank you.

This topic has been closed for replies.
Correct answer moccamaximum

It depends how you load your levels.

if you attach an event listener to Buttonbs that load your level , you could

add sth. like

function init():void{

    var maxLevels:int= int(showCookie());

   var totalLevels:int = 4

   //say it returns "2"

   for (var i:int = 1; i<=totalLevels;i++){

       if(i<=maxLevels){

       getChildByname("level"+i).visible = true;

      }

          else{

     getChildByname("level"+i).visible = false;

     }

  }

}

and in your MouseEvent.CLICK, startLevel that you add to all the buttons

you write sth. like

function startLevel(e:MouseEvent):void{

        var levelLoader:Loader = new Loader();

        levelLoader.load(new URLRequest("level"+e.currentTarget.name.substr(5,1)+".swf");

}

1 reply

Inspiring
February 12, 2013

If you want the user to be able to play the unlocked levels the next time he visits your game, LocalSharedObject is a good way to save his progress.

var cookie:String;

var LSO:SharedObject = SharedObject.getLocal("cams_zalzos_game");

//public function to set the variable in the SharedObject

function setVal(key:String, val:String)

{

    PM_LSO.data.pm_user[key] = val;

    //trace(key + " set to " + val);

    PM_LSO.flush();

}

function getVal(key:String):String

{

    return PM_LSO.data.pm_user[key];

}

function showCookie():String{

    cookie =getVal("maxLevel");

    //trace("COOKIE:"+cookie);

    return cookie;

}

//HOW TO USE IT

//If your user finishes Level 1 you call

//setVal("maxLevel","2");

//if he finishes Level 2 you call

//setVal("maxLevel","3"); etc.

//When your game starts you detect the users progress

//and making the next levels (or buttons that lead to your next Level)visible

//similar to this (adapt it to your needs)

function init():void{

    var maxLevels:int= int(showCookie());

   //say it returns "2"

   for (var i:int = 1; i<=maxLevels;i++){

       getChildByname("level"+i).visible = true;

  }

}

Inspiring
February 12, 2013

Thank you for the reply. What if my levels are all external swfs that I have connected in the Game Menu. Will the code still be the same?

moccamaximumCorrect answer
Inspiring
February 12, 2013

It depends how you load your levels.

if you attach an event listener to Buttonbs that load your level , you could

add sth. like

function init():void{

    var maxLevels:int= int(showCookie());

   var totalLevels:int = 4

   //say it returns "2"

   for (var i:int = 1; i<=totalLevels;i++){

       if(i<=maxLevels){

       getChildByname("level"+i).visible = true;

      }

          else{

     getChildByname("level"+i).visible = false;

     }

  }

}

and in your MouseEvent.CLICK, startLevel that you add to all the buttons

you write sth. like

function startLevel(e:MouseEvent):void{

        var levelLoader:Loader = new Loader();

        levelLoader.load(new URLRequest("level"+e.currentTarget.name.substr(5,1)+".swf");

}