I have some issues with getting access to display objects when using Director with multiple packages. Here’s my scenario:
I have declared a global director variable in my main.lua file, and initaited Director the recommended way. I chose to the director variable global because of my need to access display objects from other packages.
director = require("director")
mainGroup = display.newGroup()
mainGroup:insert(director.directorView)
Then I load for example “mainmenu.lua” as the first scene, and from here I load different scenes using Director. All this works fine.
But I also have another lua file, let’s call it “common_funcs.lua”. I then use a function in this file as the event listener for “enterFrame”, regardless of which lua file is currently my main scene. This function then needs to be able to access individual display objects that I created in each scene file.
I was hoping that just addressing them with director.currentView.whateverObject would work, but this is not the case. Instead I found that I can get to them using a rather awkward reference to mainGroup:
sceneGroup = ((mainGroup[1])[2])[1]
And then sceneGroup.whateverObject works fine.
Again, this works fine, but when I remove the event listener for “enterFrame” and then add it again later, the reference to my display object changes, i.e. the above “awkward” reference is no longer valid. So I can re-define the reference, but next time I disable and enable the event listener, I am in trouble again.
There is surely an easier way to get access to the display objects of the current scene from “outside”, hoping for your assistance!
Thanks,
/Leif [import]uid: 10329 topic_id: 8951 reply_id: 308951[/import]