Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hi. Really need help.

Explorer ,
Feb 12, 2013 Feb 12, 2013

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.

TOPICS
ActionScript
534
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Feb 12, 2013 Feb 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 butt

...
Translate
Guru ,
Feb 12, 2013 Feb 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;

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2013 Feb 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 12, 2013 Feb 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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2013 Feb 12, 2013
LATEST

It is working now! Thank you for the great help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines