I've created a static class in Flash which works as the inventory delegate for this game. Flash though keeps giving me this error:
ArgumentError: Error #1063: Argument count mismatch on Inventory(). Expected 1, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Main()
I've looked through the code and can't for the life of me find the source of the error. When I run the movie in debug mode it tells me that the error can be found in line 8 in Main(), which is the document class, and currently holds no code besides an empty constructor. Line 8 is where the constructor starts.
The Inventory class looks like so:
package {
import flash.display.MovieClip;
import flash.utils.getDefinitionByName;
public class Inventory extends MovieClip{
private static var instance:Inventory;
private var invItemQuant:int;
public function Inventory(pvt:PrivateClass){
invItemQuant = 0;
}
public static function getInstance():Inventory{
if(Inventory.instance == null){
Inventory.instance = new Inventory(new PrivateClass());
}
return Inventory.instance;
}
//Usage: x.addToInventory(itemName);
//After: item has been added to the inventory
public function addToInventory(itemName:String){
var itemType:Class = getDefinitionByName(itemName) as Class;
var theItem:MovieClip = new itemType();
theItem.name = itemName;
invItemQuant++;
MovieClip(getChildByName("itemSlot" + invItemQuant)).fillSlot(theItem);
}
//Usage: x.removeFromInventory(itemName);
//Before: item is contained in inventory
//After: item has been removed from the inventory
public function removeFromInventory(itemName:String){
for(var i:int = 1; i <= invItemQuant; i++){
MovieClip(getChildByName("itemSlot" + i)).emptySlot(itemName);
}
invItemQuant--;
}
//Usage: q = getItemQuant();
//Before: q is int
//After: the number of items in inventory is in q
public function getItemQuant():int{
return invItemQuant;
}
}
}
class PrivateClass {
public function PrivateClass(){
trace("PrivateClass called");
}
}
I made it static so I could access it from stage and add items to the inventory. The Inventory MovieClip is then made of equally big slots named itemSlot1, itemSlot2, etc.
The inventory slots are then linked to this class:
package {
import flash.display.MovieClip;
public class InvSlot extends MovieClip {
public function InvSlot() {
}
//Usage: x.fillSlot(itemName);
//Before: slot is empty
//After: object theItem has been put into the slot
public function fillSlot(theItem:MovieClip){
this.addChild(theItem);
}
//Usage: x.emptySlot(itemName);
//Before: movieclip itemname may exist in this object
//After: movieclip itemname does not exist in this object
public function emptySlot(itemName:String){
}
}
}
I haven't made the emptySlot method yet. The fillSlot method just adds the received movieClip to it self.
Finally I have the stageItem which when interacted with (currently just clicked) should be added to the inventory.
package {
import flash.events.MouseEvent;
public class StageItemRubberChicken extends StageItemBase{
public function StageItemRubberChicken() {
description = "It's a chicken, of the rubbery kind";
descriptiveName = "Rubber Chicken";
itemName = "ItemRubberChicken";
this.addEventListener(MouseEvent.CLICK, interactWithItem, false, 0, true);
}
private function interactWithItem(e:MouseEvent){
var mainInventory:Inventory = Inventory.getInstance();
mainInventory.addToInventory(itemName);
this.parent.removeChild(this);
}
}
}