In this tutorial i will show you how to save/load and how to make a context menu.

I start with save and load.
We need to save and load variables when we want to continue our game.

At first create a new variable called "savefile"
Code:
var savefile
Now we need to get the file where the variables are saved. We use the funrion "SharedObject.getLocal(" - file name -")"
We call our savefile "savegame".
Now we load it.
Code:
savefile = SharedObject.getLocal("savegame")
Now we can save, but we need to write the variables at first. We have follow variables: Health; Money; Level; EXP
Code:
savefile.data.health = _root.Health
savefile.data.money= _root.Money
savefile.data.level= _root.Level
savefile.data.exp= _root.EXP
savefile.flush()
Then we use the flush function which saves.
Now we saved variables, good work.

[color=#FF0000]Note: If you are using arrays, there might be a problem. If the savefile is on root and the origin array is changed, the array in the savefile is changed, too. Solution: Use an instanztvariable.[/color]

Now we load:
We are using a return value. So we can controll if there is a savefile.
Code:
function load_game():Boolean{
  savefile = SharedObject.getLocal("savegame")
  if(savefile.data.money != undefined){
    _root.Money = savefile.data.money
    _root.Health = savefile.data.health
    _root.Level = savefile.data.level
    _root.EXP = savefile.data.exp
    return true
  }
  return false
}
If there is a savefile, the function loads the variables and returns true. If not it returns false.



Now we make the context menu.

Everyone knows it, right click and play to cheat. We want to disable it.
To disale it, we need to create a new context menu:
Code:
var my_Menu = new ContextMenu()
Now we can edit it. At first we disable the build in items:
Code:
myMenu.hideBuiltInItems()
[color=#FF0000]<---------- You dont have to do this, but i suggest it ---------->[/color]
Enable the quality item:
Code:
myMenu.builtInItems.quality = true
[color=#FF0000]<---------------------------------------------------------------------->[/color]

Before we add a new item in our new menu, we need a funtion for the item first:
Code:
function test_function(){
  trace("Hello") //Output on the debugconsole
}
Now we add a new item:
Code:
myMenu.customItems.push(new ContextMenuItem("My new item ^^", test_function))
Now we need a final step:
Code:
_root.menu = myMenu
Now build it and run it in debugmode. Right click and click the new item. You should see something in the debugconsole.

Some random infos:
  • Every custom item is in an array
  • The name is "customItems"
  • You can change the displayed text.
    Code:
    _root.menu.customItems[- number of the item -].caption = "- new text -"