0

item というクラスを作成しました。このクラスは、関数 itemdata() で変数を返します。このクラスのオブジェクト インスタンスを作成し、これを介して別のオブジェクトに追加しています。

//Item Creation

function additem(Name:String,file:Class,workswith:String,tu rnsinto:String,examine:String,X:Number,Y:Number) {
var itemname:item = new item();
var ItemDB:Array= new Array();
itemname.create(Name,file,workswith,turnsinto,exam ine,X,Y);
itemname.addChild(itemname.itemdata("filename")); 
ItemDB.push(itemname);
var itemindb:int = ItemDB.length-1;
Items.addChild(ItemDB[itemindb]);
}

//--

ただし、アイテムをクリックした後にアイテムの変数にアクセスしようとすると (次の方法で:)

stage.addEventListener (MouseEvent.CLICK,InventoryPickup);
function InventoryPickup(event:MouseEvent):void {
var t:DisplayObject = DisplayObject(event.target);
if (t.parent==Items){
t.itemdata();
}
}

次のようなエラーが表示されます。

1061: Call to a possibly undefined method itemdata through a reference with static type flash.display:DisplayObject.

私が間違っていることは何か分かりますか?ありがとう!

4

1 に答える 1

0

var t を定義したため、クラスDisplayObjectのインスタンスではないため、メソッド itemdata がありません... これを試してください:Item

var t:Item = Item(event.target); 

それ以外の:

var t:DisplayObject = DisplayObject(event.target);
于 2013-05-03T17:20:04.637 に答える