Question

Back when I did LUA i used to run dofile("..."); to load other lua files and such. Later to find out that this is a very bad practice and can lead to applications breaks.

Now that I am on my way to developing a WebOs application, i want to make sure I am properly changing scene before i pick up bad programming habit.

At the moment this is what I use:

label2Tap: function(inSender, event) {
    Mojo.Controller.stageController.popScene();
    Mojo.Controller.stageController.swapScene("LogicAndArithmetic");
},

Which works great to get to my LogicAndArithmetic scene, is this the best practice to do such? Thanks.

Was it helpful?

Solution

The scene model in the Mojo framework of webOS works like a stack. When the app starts you call pushScene to display your main scene. Normally, you then make additional pushScene calls to add scenes to the stack on top, and then when you are done with them they are popped, typically when the user performs the 'back gesture', bringing back the previous scene. Eventually you will be back at your main scene.

The swapScene call is equivalent to calling popScene and then pushScene for a different scene. In your case you are calling popScene then swapScene, so that is the equivalent of popping two scenes from the stack and then pushing back one. It probably works because you have only one scene, but if you had more it would not work correctly.

BTW, why are you working with Mojo and not Enyo?

OTHER TIPS

While this is technically correct, it is most likely not how the user would expect your app to behave. In general, when a user presses a button that opens a new scene, it is placed on the stack, as Miguel said. The user will expect to be able to go back and pop the scene off of the stack. This happens automatically, you do not need to listen for this input. You do this by calling Mojo.Controller.pushScene("sceneName");. While there are some applications where swapScene makes sense, your app can probably be conceptualized as a stack of scenes, with a logical "back" scene.

I would reccommend playing around with some existing apps to get a feel for how they behave. Also, while Miguel suggested moving to Enyo, it is worth noting that Enyo apps are not officially supposed to work on webOS 2 devices (phones), only on the touchpad. It is possible to run them on webOS 2 devices, but I do believe that they will be rejected from the app catalog.

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