[]【求助】关于Cannot read property 'visible' of undefined问题
我的代码是这样子的:
private function showFoods():void{currentFood也是Food类,是用来指向在foodList中处于下标index的元素,我是想在用currentFood指向某个元素,给这个元素添加事件,让其可以执行一些动作,但是这段代码运行后,报出了Cannot read property 'visible' of undefined这个错误:
foodSprite = new Sprite();
Laya.stage.addChild(foodSprite);
this.index = 0;
foodsList = new Array();
foodsList.push(new Food("菜品1", "1", 0));
foodsList.push(new Food("菜品2", "2", 1));
foodsList.push(new Food("菜品3", "3", 2));
foodsList.push(new Food("菜品4", "4", 3));
foodsList.push(new Food("菜品5", "5", 4));
foodSprite.addChildren(foodsList);
addFoodListener();
}
private function addFoodListener():void{
console.log(foodsList[this.index]);
this.currentFood = this.foodsList[this.index];
console.log(currentFood);
this.currentFood.on(Event.MOUSE_DOWN, this, onMouseDown);
this.currentFood.on(Event.MOUSE_UP, this, onMouseUp);
}
TypeError: Cannot read property 'visible' of undefined求高手解答,或者可以实现我这个需求的另一种思路,谢谢各位了。
at RenderSprite3D.__proto._childs (file:///D:/Projects/Study/three/bin/h5/Main.max.js:6529:29)
at Sprite.__proto.render (file:///D:/Projects/Study/three/bin/h5/Main.max.js:21868:42)
at RenderSprite3D.__proto._childs (file:///D:/Projects/Study/three/bin/h5/Main.max.js:6529:45)
at RenderSprite3D.__proto._transform (file:///D:/Projects/Study/three/bin/h5/Main.max.js:20706:15)
at Stage.__proto.render (file:///D:/Projects/Study/three/bin/h5/Main.max.js:21868:42)
at Stage.__proto.render (file:///D:/Projects/Study/three/bin/h5/Main.max.js:25799:29)
at Stage.__proto._loop (file:///D:/Projects/Study/three/bin/h5/Main.max.js:25729:8)
at loop (file:///D:/Projects/Study/three/bin/h5/Main.max.js:5798:15)
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Laya_XS
赞同来自: