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.
私が間違っていることは何か分かりますか?ありがとう!