@vincent_jie wrote:
Hierarchy of nodes:
MainScene
|----Parent
|----|----ChildCodes
ParentCom.lua
local M = {} function M:printSelf() cc.log("This is Parent"); end return M
ChildCom.lua
local M = {} function M:printSelf() print("This is Child"); end return M
MainScene.lua
local root = self:getResourceNode() local parent = root:getChildByName("Parent") local child = parent:getChildByName("Child") local parentCom = cc.ComponentLua:create("app/views/ParentCom.lua") parentCom:setName("ParentComponent") parent:addComponent(parentCom) local childCom = cc.ComponentLua:create("app/views/ChildCom.lua") childCom:setName("ChildComponent") child:addComponent(childCom) parentCom:printSelf()
Then the
parentCom:printSelf()
output isThis is Child:
. Why does this happen?
Posts: 1
Participants: 1