How to get "self.view" from a event listener or callback in storyboard scene

For regular scene event handler, for example

    function scene:createScene( event )

    local group = self.view
  end

I can access the associated display group by “self.view”, however for my own callback or other event listener (such as touch event)

    local function touchListener (self, touch)   – self is a background display object 

    local function httpCallback (data)              – a callback function from an async http request

Within these two functions, how to access the associated display group of the scene, like the “self.view” in createScene()?

Thanks.

Touch events are nothing to do with the storyboard API, so you can’t. If you need to pass scene view information from objects listening for touch events to the event listener you’ll need to provide a property on the object.

I suspect that you are structuring your scene incorrectly as there are many ways to provide the current scene without needing to pass it in incorrect code locations.

Why do you think you need to take the scene info from the touch event?

Btw, when posting code, use the <> button to show it as a code snippet.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local function httpCallback(data) end local function touchListener (self, touch) end function scene:createScene( event ) local group = self.view background = display.newRect( 0, 0, screenW, screenH-navBarHeight) background:addEventListener( "touch", background ) end function scene:enterScene( event ) local group = self.view some\_module.myHttpRequest(httpCallback) end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

Please see the code above. This is the structure of my scene file.

My question is, for those two functions:

    local function touchListener (self, touch)

    local function httpCallback(data)

How do I get to access the associated display group? For example, in scene:createScene() or other scene event listener functions, it is  “self.view”.  

Yes, I am new to Corona SDK. Please help, I am trying to learn. Thanks a lot.

I found a way to get what I want:

storyboard.getScene("mySceneName").view

Is this the answer?

Or is there something I should change in the code structure instead? I am also wondering if there is some fundamentally improper structure in my code.

That will get the named scene. I would have used storyboard.getCurrentSceneName() instead of “mySceneName”

So for my question, just to use

storyboard.getScene(storyboard.getCurrentSceneName()).view

that’s all?

The answer I was really looking for is

scene.view

That’s all.

Touch events are nothing to do with the storyboard API, so you can’t. If you need to pass scene view information from objects listening for touch events to the event listener you’ll need to provide a property on the object.

I suspect that you are structuring your scene incorrectly as there are many ways to provide the current scene without needing to pass it in incorrect code locations.

Why do you think you need to take the scene info from the touch event?

Btw, when posting code, use the <> button to show it as a code snippet.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local function httpCallback(data) end local function touchListener (self, touch) end function scene:createScene( event ) local group = self.view background = display.newRect( 0, 0, screenW, screenH-navBarHeight) background:addEventListener( "touch", background ) end function scene:enterScene( event ) local group = self.view some\_module.myHttpRequest(httpCallback) end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

Please see the code above. This is the structure of my scene file.

My question is, for those two functions:

    local function touchListener (self, touch)

    local function httpCallback(data)

How do I get to access the associated display group? For example, in scene:createScene() or other scene event listener functions, it is  “self.view”.  

Yes, I am new to Corona SDK. Please help, I am trying to learn. Thanks a lot.

I found a way to get what I want:

storyboard.getScene("mySceneName").view

Is this the answer?

Or is there something I should change in the code structure instead? I am also wondering if there is some fundamentally improper structure in my code.

That will get the named scene. I would have used storyboard.getCurrentSceneName() instead of “mySceneName”

So for my question, just to use

storyboard.getScene(storyboard.getCurrentSceneName()).view

that’s all?

The answer I was really looking for is

scene.view

That’s all.