Here's my script:
_global.loadInvItem = function(number:Number) {
var localItemName:String = _global.inventory[number];
if (localItemName == "undefined") {
break;
} else {
globalItemName = searchArray(localItemName, itemName);
itemInstance = itemInst[globalItemName];
_root.bar.attachMovie(itemInstance, "item"+i, i);
_global.itemSlotsUsed++;
_root.bar["item"+i]._y = 97;
_root.bar["item"+i]._x = 515.7+((number%6)*75);
_root.bar["item"+i].id = globalItemName;
_root.bar["item"+i].onRollOver = function() {
this.rollingOver = true;
};
_root.bar["item"+i].onRollOut = function() {
this.rollingOver = false;
_root.itemNameBox.nameText.text = "";
_root.itemNameBox._x = -10000;
_root.itemNameBox._y = -10000;
};
_root.bar["item"+i].onEnterFrame = function() {
if(!this.yetStarted) {
this.startX = this._x;
this.startY = this._y;
this.yetStarted = true;
}
if (!this.isMoving and this.rollingOver) {
_root.itemNameBox._x = this._x;
_root.itemNameBox._y = this._y-10;
_root.itemNameBox.nameText.text = _root.itemName[this.id];
}
if (this.isMoving) {
_root.itemNameBox.nameText.text = "";
_root.itemNameBox._x = -10000;
_root.itemNameBox._y = -10000;
}
};
_root.bar["item"+i].onPress = function() {
this.isMoving = true;
startDrag(this, true);
};
if (itemType[globalItemName] == "Food") {
_root.bar["item"+i].onRelease = function() {
this.isMoving = false;
this.stopDrag();
if (this.hitTest(_root.bar.buddyBox)) {
fullMod = _root.itemFull[this.id];
healthMod = _root.itemHealth[this.id];
happyMod = _root.itemHappy[this.id];
_global.food += fullMod;
_global.health += healthMod;
_global.happy += happyMod;
_global.removeInvItem(_root.itemName[this.id]);
if (happyMod>0) {
_global.displayQuote("Yum, that tasted good!", true);
} else if (healthMod>=1) {
_global.displayQuote("Do I have to?", true);
} else {
_global.displayQuote("Uhhh.... what on earth is this?", true);
}
_global.refreshInv();
} else {
this._x = this.startX;
this._y = this.startY;
}
};
} else if (itemType[globalItemName] == "Toy") {
_root.bar["item"+i].onRelease = function() {
this.isMoving = false;
this.stopDrag();
if (this.hitTest(_root.bar.buddyBox)) {
happyMod = _root.itemHappy[this.id];
_global.happy += happyMod;
if (happyMod<25 and happyMod>10) {
_global.displayQuote("That was fun!", true);
} else if (happyMod<=10 and happyMod>=1) {
_global.displayQuote("Ehh... that was pretty boring", true);
} else if (happyMod<1) {
_global.displayQuote("BOOOORING!", true);
} else {
_global.displayQuote("Woohooo! This is soooooo much fun!!!!", true);
}
breakChance = Math.round(Math.random()*10);
if (breakChance != 1) {
brokenName = "Broken "+_root.itemName[this.id];
_global.addInvItem(brokenName);
_global.removeInvItem(_root.itemName[this.id]);
_global.refreshInv();
}
} else {
this._x = this.startX;
this._y = this.startY;
}
};
} else if (itemType[globalItemName] == "Broken Toy") {
_root.bar["item"+i].onRelease = function() {
this.isMoving = false;
this.stopDrag();
if (this.hitTest(_root.bar.buddyBox)) {
_global.displayQuote("I can't play with that!", true);
}
this._x = this.startX;
this._y = this.startY;
};
}
i++;
}
};
Everything works, except for that the onRelease for broken toys never calls. The syntax has no errors, according to flash. Help please!