Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

添加组件失败:addComponent: The component to add must be a constructor

$
0
0

@745872343 写道:

创建childClass类,继承于cc.Component,然后获取实例化对象childJS,将childJS作为组件添加到节点,失败。求大神指点~

  var childClass = cc.Class({
            extends: cc.Component,
            properties: {

            },
            onload: function (dt) {
                    cc.error('hello, child');
            },
            clickTest: function () {
                    cc.log('click Test');

            }
    });
    
    var childJS = new childClass();
    
    var childNode = new cc.Node('childNode');
    
    childNode.addComponent(childJS);

    this.node.addChild(childNode);

报错信息:
Simulator: addComponent: The component to add must be a constructor

应该在哪里添加构造函数吗,看了官方文档,但不太懂~

帖子: 3

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>