How can I create a Back button that goes to the previous scene?
Greetings Borisbroekie [import]uid: 203192 topic_id: 34024 reply_id: 334024[/import]
How can I create a Back button that goes to the previous scene?
Greetings Borisbroekie [import]uid: 203192 topic_id: 34024 reply_id: 334024[/import]
There are dozens of ways for creating a button, but to go back a scene you can call storyboard.getPrevious() to get the name of the scene you just came from. Perhaps something like this:
local widget = require("widget")
local function goBack(event)
if event.phase == "release" then
storyboard.gotoScene(storyboard.getPrevious())
end
return true
end
local myButton = widget.newButton{
id = "btn001",
left = 100,
top = 200,
label = "Widget Button",
width = 150, height = 28,
cornerRadius = 8,
onEvent = goBack
}
group:insert( myButton )
[import]uid: 199310 topic_id: 34024 reply_id: 135315[/import]
If I am completely off then please ignore this post. It is early and am too lazy to test it.
But if I remember correctly, you have to assign the storyboard.getPrevious() to a variable before the scene is “loaded”/moved on screen. Else the get.previous will think it is the current scene the current scene.
I use the get.previous to see which screen I came form. I can remember I had to do this to make it work. Might be changed or maybe I did something else wrong. [import]uid: 100901 topic_id: 34024 reply_id: 135407[/import]
I took care of the double post.
Now for the storyboard.getPrevious() call… I remember seeing that behavior when I was doing my Yosemite photo gallery project and it was pretty frustrating. But I just ran a test where I printed the value at the beginning and end of the createScene() function and at the beginning and end of the enterScene() function and the values were what I expected, so perhaps this is a bug that was fixed.
Still to be safe, it doesn’t hurt to capture the value at the beginning of the createScene phase and save the value to be used later in the scene. [import]uid: 199310 topic_id: 34024 reply_id: 135541[/import]
There are dozens of ways for creating a button, but to go back a scene you can call storyboard.getPrevious() to get the name of the scene you just came from. Perhaps something like this:
local widget = require("widget")
local function goBack(event)
if event.phase == "release" then
storyboard.gotoScene(storyboard.getPrevious())
end
return true
end
local myButton = widget.newButton{
id = "btn001",
left = 100,
top = 200,
label = "Widget Button",
width = 150, height = 28,
cornerRadius = 8,
onEvent = goBack
}
group:insert( myButton )
[import]uid: 199310 topic_id: 34024 reply_id: 135315[/import]
If I am completely off then please ignore this post. It is early and am too lazy to test it.
But if I remember correctly, you have to assign the storyboard.getPrevious() to a variable before the scene is “loaded”/moved on screen. Else the get.previous will think it is the current scene the current scene.
I use the get.previous to see which screen I came form. I can remember I had to do this to make it work. Might be changed or maybe I did something else wrong. [import]uid: 100901 topic_id: 34024 reply_id: 135407[/import]
I took care of the double post.
Now for the storyboard.getPrevious() call… I remember seeing that behavior when I was doing my Yosemite photo gallery project and it was pretty frustrating. But I just ran a test where I printed the value at the beginning and end of the createScene() function and at the beginning and end of the enterScene() function and the values were what I expected, so perhaps this is a bug that was fixed.
Still to be safe, it doesn’t hurt to capture the value at the beginning of the createScene phase and save the value to be used later in the scene. [import]uid: 199310 topic_id: 34024 reply_id: 135541[/import]