Question

I only know basics in using storyboard. I created a scene without problem, and then I added my own callback (returned from a asynchronous http request). Therefore in my scene Lua file, I have following

local function httpCallback(data) 

// process data

// screen update

end

For "screen update", I don't have access to the associated display group, which I mean the "self.view" in the scene listeners, for example,

function scene:createScene( event )
    local group = self.view
end

How do I get access to the "self.view"? I was thinking to use a variable to track self.view, but with "asynchronous" callback, I am afraid self.view would have become nil before I find out?

What's the proper way for this?

Thanks.

Was it helpful?

Solution

At the top of your storyboard module you should have the line:

local scene = storyboard.newScene()

or something similar. This is your scene. for the event handlers like createScene() and such they get passed "scene' as "self". Therefore you can always (after createScene() is first called) refer to the scene's view (a display.newGroup for all intents and purposes) using the code:

scene.view:insert(someDisplayObject)

which means you can also do:

local group = scene.view

and then use the group reference if you prefer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top