cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
paopao_node: cc.Node,
answerPrefab: cc.Prefab,
},
// use this for initialization
onLoad: function () {
this.createOption();
},
createOption: function () {
//console.log("interactiveJson: "+interactiveJson[0].options.length);
var optionsLength = 5;
//var answerArr = interactiveJson[0].options;
//console.log("answerArr[i].optioncontent: "+answerArr[0].optioncontent);
var stageWidth = this.node.width;
var bWidth = 244;
var bHeight = 238;
var dd = 100;
var dx = (stageWidth - (optionsLength - 1)*dd - optionsLength*bWidth)/2 + bWidth/2;
console.log("someloc: "+stageWidth+" "+optionsLength+" "+dx);
for(var i=0; i<optionsLength; i++)
{
var btn = cc.instantiate(this.answerPrefab);
btn = node.getComponent(cc.Button);
btn.x = dx + i*dd + i*bWidth;
btn.y = bHeight;
btn.name = "btn"+i.toString();
var answerLabel = btn.getChildByName("answerLabel");
answerLabel.getComponent(cc.Label).string = i.toString();
//btn = this.node.getComponent(cc.Button);
//btn.node.clickEvents.push(this.clickEventHandler);
this.paopao_node.addChild(btn);
btn.on('click', this.clickBtn, this);
//this.btnPool.put(btn);
}
},
clickBtn: function (event)
{
console.log("iiiiii");
console.log(event.detail);
},
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});