我有一个处理时间表的库存系统。现在,我正试图将它连接到一个班级,但我遇到了困难。
在我的舞台上,我有MovieClip
,其实例名称为InventoryMc
在InventoryMc
内,我还有15个MovieClips
,其实例名称为itemSlot1
,itemSlot2
等... gotoAndStop
函数无法正常工作...
我没有文档类,只有扩展MovieClips
...
这是我的BeginnerChest
类,点击它时会调用Inventory
类中的函数:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class BeginnerChest extends MovieClip {
private var _inventory:Inventory;
public function BeginnerChest() {
_inventory = new Inventory();
addEventListener(MouseEvent.CLICK, begClick);
claimBtn.addEventListener(MouseEvent.CLICK, _inventory.claimClick);
}
public function begClick(e: MouseEvent) {
play();
} //ends startBtnClick;
public function insertText(str) {
return str + "\r"
}
}
}
这是我的Inventory
课......我拿出了其他我认为不必要的功能。我试图让这个addToslot
函数起作用,但它似乎永远不会找到框架Hammer
或它是什么。是的,我确实在itemSlots
MovieClip内标记了它。
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.events.Event;
public class Inventory extends MovieClip{
var Slot1: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot2: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot3: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot4: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot5: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot6: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot7: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot8: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot9: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot10: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot11: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot12: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot13: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot14: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var Slot15: Array = ["empty", "empty", 0]; //[ItemId, Display Name, Sell Price]
var slotClicked: String;
var NewItem = "None";
var BoxesReset: Boolean = false;
var InventoryFull: Boolean = false;
var ItemSelected = "";
var ItemUse = "None";
var CurrentSlot = "None";
var CurrentSlot2 = "None";
var ItemId = "None";
var StoreMode: Boolean = false;
var ItemSellPrice = 0;
var ItemName = "";
var totalChildren = 0;
///// Dynamic Variables /////
var container: MovieClip = new MovieClip;
var btnUse: MenuItem = new MenuItem;
var btnToss: MenuItem = new MenuItem;
var btnClose: MenuItem = new MenuItem;
public function Inventory() {
addEventListener(MouseEvent.CLICK, ItemSlotClick);
}
public function InventoryFullCheck() {
if (Slot1[0] != "empty" && Slot2[0] != "empty" && Slot3[0] != "empty" && Slot4[0] != "empty" && Slot5[0] != "empty" && Slot6[0] != "empty" && Slot7[0] != "empty" && Slot8[0] != "empty" && Slot9[0] != "empty" && Slot10[0] != "empty" && Slot11[0] != "empty" && Slot12[0] != "empty" && Slot13[0] != "empty" && Slot14[0] != "empty" && Slot15[0] != "empty") {
InventoryFull = true;
} else {
InventoryFull = false;
}
}
public function claimClick(e: MouseEvent): void {
addToslot(Hammer);
}
public function addToslot(item) {
if (Slot1[0] == "empty") {
CurrentSlot = "itemSlot1";
(item)(); <---------------------does hammer function at bottom
} else if (Slot2[0] == "empty") {
itemSlot2.gotoAndStop(item);
Slot2[0] = item;
} else if (Slot3[3] == "empty") {
itemSlot3.gotoAndStop(item);
Slot3[0] = item;
} else if (Slot4[0] == "empty") {
itemSlot4.gotoAndStop(item);
Slot4[0] = item;
} else if (Slot5[0] == "empty") {
itemSlot5.gotoAndStop(item);
Slot5[0] = item;
} else if (Slot6[0] == "empty") {
itemSlot6.gotoAndStop(item);
Slot6[0] = item;
} else if (Slot7[0] == "empty") {
itemSlot7.gotoAndStop(item);
Slot7[0] = item;
} else if (Slot8[0] == "empty") {
itemSlot8.gotoAndStop(item);
Slot8[0] = item;
} else if (Slot9[0] == "empty") {
itemSlot9.gotoAndStop(item);
Slot9[0] = item;
} else if (Slot10[0] == "empty") {
itemSlot10.gotoAndStop(item);
Slot10[0] = item;
} else if (Slot11[0] == "empty") {
itemSlot11.gotoAndStop(item);
Slot11[0] = item;
} else if (Slot12[0] == "empty") {
itemSlot12.gotoAndStop(item);
Slot12[0] = item;
} else if (Slot13[0] == "empty") {
itemSlot13.gotoAndStop(item);
Slot13[0] = item;
} else if (Slot14[0] == "empty") {
itemSlot14.gotoAndStop(item);
Slot14[0] = item;
} else if (Slot15[0] == "empty") {
itemSlot15.gotoAndStop(item);
Slot15[0] = item;
} else {
InventoryFull = true;
}
}
public function ClearVars(): void {
ItemUse = "None";
ItemId = "None";
ItemSelected = "None";
HideSelectBoxes();
}
public function Hammer(): void {
trace(CurrentSlot);
Object(root).InventoryMc.itemSlot1.gotoAndStop("Hammer"); <---can't get this to work...
}
} //ends class
} //ends package