cocos2d-js取不到cocostudio里面控件问题

var winSize = cc.director.getWinSize();

        //add main node
        var mainNode = cc.Node.create();
        var scale = winSize.height / 320;
        mainNode.attr({anchorX: 0, anchorY: 0, scale: scale, x: (winSize.width - 480 * scale) / 2, y: (winSize.height - 320 * scale) / 2});
        this.addChild(mainNode);

        //read widget
        var widget = ccs.uiReader.widgetFromJsonFile(res.ui_start);
        mainNode.addChild(widget,-1);

        //var widget = ccs.uiReader.widgetFromJsonFile(res.ui_start);
        //this.addChild(widget,100);

// 取得父节点 var a = widget.getChildByName("ImageView_50"); // 取得父节点上的按钮 var left_button = a.getChildByName("Button_shengcun"); left_button.addTouchEventListener(this.onNewGame ,this);

新版本里的getChildByName函数已经不会遍历所有控件了,它仅仅会去当前控件下的子控件里去找,所以子控件的子控件就获取不到了

你可能感兴趣的:(cocos2d-js)