Cocos creator中出现Uncaught TypeError: Cannot read property 'node' of undefined
来源:互联网 发布:富安娜淘宝旗舰店 编辑:程序博客网 时间:2024/06/05 03:16
最近在学习Cocos creator开发cocos游戏,总体感觉比较好,但是由于cocos creator开发游戏主要使用JavaScript开发的,所以很多语法都不是很清楚,所以就出现了一些问题。
今天在动态加载resources文件夹下的图片资源就出现了一些问题,根据官方文档进行资源的动态加载:
// 加载 SpriteFramecc.loader.loadRes("test assets/image", cc.SpriteFrame, function (err, spriteFrame) { this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;});
然而却出现浏览器报错如下:
Uncaught TypeError: Cannot read property 'node' of undefined at OnePersonScene.js:143 at CCLoader.<anonymous> (CCLoader.js:446) at CCLoader.js:238 at utils.js:85刚开始根据报错的提示,以为是这个节点没有定义,但是检查编辑器发现这个节点貌似没问题,可是就是这样报错的,没办法就把这个节点删除了重新添加,可是运行之后仍然是这个问题,然后就感觉可能是错误提示的有问题,问题可能不是因为这个节点没有定义,只好从别的方面入手,然后我就对着官方给的文档一个字母一个字母的对照终于发现了一个问题,官方文档如下:
// 加载 SpriteFramevar self = this;cc.loader.loadRes("test assets/image", cc.SpriteFrame, function (err, spriteFrame) { self.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;});然后发现问题在于官方文档在函数体外定义一个变量 var self = this;但是我却是直接在函数体中直接使用this,唯一的不同就在这里,可能这就是问题,修改之后再运行,果然没有问题了,可是不明白为什么要这么做,在网上也没找到答案,有点小纠结~不过好在错误解决了,还是有点收获的,以后记得注意~
阅读全文
0 0
- Cocos creator中出现Uncaught TypeError: Cannot read property 'node' of undefined
- Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
- 【StackFlow】Uncaught TypeError: Cannot read property 'pageCount' of undefined
- Ckeditor: Uncaught TypeError: Cannot read property 'keyCode' of undefined 解决方法
- Uncaught TypeError: Cannot read property 'msie' of undefined问题解决方案
- Uncaught TypeError: Cannot read property 'options' of undefined 错误
- Uncaught TypeError: Cannot read property 'length' of undefined
- 错误:Uncaught TypeError: Cannot read property 'WebSocket' of undefined
- Uncaught TypeError: Cannot read property 'value' of undefined
- Uncaught TypeError: Cannot read property 'plugin' of undefined
- react Uncaught TypeError: Cannot read property 'title' of undefined
- Uncaught TypeError: Cannot read property 'width' of undefined
- Uncaught TypeError: Cannot read property 'substring' of undefined
- Uncaught TypeError: Cannot read property 'PRINT_INIT' of undefined user:100
- Uncaught TypeError: Cannot read property 'substring' of undefined
- extjs4:Uncaught TypeError: Cannot read property 'processed' of undefined
- Datatables 之Uncaught TypeError: Cannot read property 'mData' of undefined
- background.js Uncaught TypeError: Cannot read property 'xxx' of undefined
- 最全Pycharm教程(11)——Pycharm调试器之断点篇
- CCF CSP 认证真题部分题解
- spoj1811 Longest Common Substring(LCS)最长公共子串
- 【兴趣书签】SOHO生活——理想的生活方式
- 最短路径算法(上)——迪杰斯特拉(Dijikstra)算法
- Cocos creator中出现Uncaught TypeError: Cannot read property 'node' of undefined
- mysql的水平拆分和垂直拆分
- 5分钟内的Maven
- linux命令替换
- 尼姆博弈
- java集合框架TreeSet的使用和HashSet的使用
- 数组基础
- 什么是Rup,介绍一下Rup。
- hdu6196 强行爆搜