当我点击场景中的苹果对象时,我的代码返回了错误1009的pickObject函数,我真的不明白为什么?我被困在这里希望得到一些帮助。
以下是我在时间轴上的代码:
//INVENTORY
import flash.events.MouseEvent;
import inventory.inventorySystem;
import inventory.itemC;
import flash.text.TextField;
var IS:inventorySystem;
var IT:itemC;
apple.itemName = "Apple";
apple.itemIcon = new AppleIcon();
apple.addEventListener(MouseEvent.MOUSE_MOVE, showItemNameF);
apple.addEventListener(MouseEvent.MOUSE_OUT, hideItemNameF);
apple.addEventListener(MouseEvent.MOUSE_DOWN, pickUpItem);
pear.itemName = "Pear";
pear.itemIcon = new PearIcon();
pear.addEventListener(MouseEvent.MOUSE_MOVE, showItemNameF);
pear.addEventListener(MouseEvent.MOUSE_OUT, hideItemNameF);
function pickUpItem(e:MouseEvent):void{
IS.addObject(itemC(e.currentTarget));
removeChild(itemC(e.currentTarget));
}
function showItemNameF(e:MouseEvent):void{
var itemNameBox:String;
itemNameBox = itemC(e.currentTarget).itemName;
stage.addChild(infoBoxObject);
infoBoxObject.infoBox.text = itemNameBox;
infoBoxObject.x = mouseX+12;
infoBoxObject.y = mouseY;
}
function hideItemNameF(e:MouseEvent):void{
infoBoxObject.x = -145;
infoBoxObject.y = 61;
}
//CURSOR
Mouse.hide();
var cursor:cursorImage = new cursorImage();
stage.addChild(cursor);
cursor.startDrag(true);
这是我的inventorySystem类:
package inventory{
public class inventorySystem{
private var slot:Array = new Array(10);
public function addObject(it:itemC){
for(var i=0;i<10;i++){
if(slot[i]==null){
slot[i] = it;
return;
}
}
}
public function getObject(i:int):itemC{
return slot[i];
}
public function useObject(i:int){
slot[i] = null;
}
}
}
这是我的itemC类:
package inventory{
import flash.display.MovieClip;
public class itemC extends MovieClip{
public var itemName:String;
public var itemIcon:MovieClip;
}
}
答案 0 :(得分:0)
声明变量IS
,但未初始化。尝试改变:
var IS:inventorySystem;
为:
var IS:inventorySystem = new inventorySystem();