PDA

View Full Version : Creating Inventory for Flash games



__FLATLINE__
October 24th, 2002, 11:35 AM
Can anyone suggest me how to create an inventory system for a flash game? Ya know, those stuff that like lets say there's a box on the screen, you click on it and it is added to your inventory, then you can select it from your inventory screen and use it for stuff.

Any ideas?

MedaXis
October 24th, 2002, 11:45 AM
try this, this code on the first frame of the main timeline, on the stage:a button with instancename "inventbutton":

inventory = new Array();
trace(inventory);
inventbutton.onPress = function()
{
currentItem = "shoe";
attachItem(currentItem);
}
function attachItem(itemName)
{
inventory.push(itemName);
trace(inventory);
}

Steve

__FLATLINE__
October 24th, 2002, 12:18 PM
thanks but how will you USE items in the inventory and how will you graphicly display them in slots?

MedaXis
October 25th, 2002, 09:01 AM
I assume you are trying to create some game like diablo?
so, you'll need healthpotions :)

to use an item you could use this code, where healthpotion is the name of the button:

health = 50;
healthpotion.onPress = function()
{
currentItem = "healthpotion";
useItem(currentItem);
}
function useItem(itemName)
{
health += 50;
_root.healthindicator.healthbar._xscale = (health/100 * 100);
}

to display the items in an inventory list, you'll need the inventory array, for every item in that array you have to create a button in the inventory movieclip

Steve