Results 1 to 18 of 18
  1.    #1  
    Ok I am having a problem with my scenes and I could do with some help...

    My application has 2 scenes.
    On the FirstAssistant.prototype.setup (scene1) I have set:

    $$('body')[0].addClassName('palm-dark');
    $$('body')[0].removeClassName('palm-default');

    and on FirstAssistant.prototype.deactivate = function(event) I have done the same. Now scene2 has exactly the same for setup and deactivate. It also has a back button which takes back to scene1 by doing this:

    SecondAssistant.prototype.prevScene = function(event){
    Mojo.Controller.stageController.pushScene("first");
    }

    Now when I use the back button to visit scene1 again, the black colour always works. When I swipe backwards the colour fails and it shows white. I thought that when the scene was visited again the setup function was run again.

    Any thought on what I am doing wrong here?
    Any help would be appreciated.
    Thanks
    Vas
  2.    #2  
    Ok I found the answer. The 2 lines of code need to run within activate and not setup.
  3. #3  
    you also might want to consider stageController.popScene() to remove the topmost scene and return to the first scene. Otherwise you are loading the first scene a second time, over the top of the previous two loaded scenes.
    My apps:
    ReWeather - Attractive weather app that reflects current conditions
    Suburbly UK (trial version) - Search for properties to rent, share or buy all over UK.

    Twitter: @joshsharp / @recursivemedia
  4. #4  
    thought I might try to clarify the situation a bit. When you push scene2, scene1 is still there, just sitting underneath scene2. If it was doing anything, I.e. Playing an animation, it keeps doing so. The back gesture simply pops scene2 taking you back to scene1. As josh said, pushing scene1 again gives you a scene stack of scene1->scene2->scene1.
    as to the scene methods, setup is run when the scene is pushed, activate is run every time the scene is brought into focus, deactivate is run whenever you switch to another scene and cleanup is run when the scene is popped. Also worth noting, activate and deactivate typically don't run when you switch to or from card view. You'll need to register separate events for that.
  5.    #5  
    Quote Originally Posted by joshsharp View Post
    you also might want to consider stageController.popScene() to remove the topmost scene and return to the first scene. Otherwise you are loading the first scene a second time, over the top of the previous two loaded scenes.
    Yes I noticed this "bi-product". I had to do several back swipes to actually reach the initial instance of the first scene. Many thanks of all your help guys. I will also check out the developer forums on the Palm site, so I don't polute this site with my coding questions. Not sure if this is aht right forum for it.

    Thanks again
    Vas
  6. #6  
    this forum is for development questions. Don't be afraid to ask coding questions here.
  7.    #7  
    Quote Originally Posted by unfairSurprisery View Post
    thought I might try to clarify the situation a bit. When you push scene2, scene1 is still there, just sitting underneath scene2. If it was doing anything, I.e. Playing an animation, it keeps doing so. The back gesture simply pops scene2 taking you back to scene1. As josh said, pushing scene1 again gives you a scene stack of scene1->scene2->scene1.
    as to the scene methods, setup is run when the scene is pushed, activate is run every time the scene is brought into focus, deactivate is run whenever you switch to another scene and cleanup is run when the scene is popped. Also worth noting, activate and deactivate typically don't run when you switch to or from card view. You'll need to register separate events for that.
    Just to clarify something....For a start assume that instead of using a back button, if I want to use the backswipe. And you have loaded scene1 -> scene2. Does the back swipe automatically pop scene2 or do I have to handle anything?

    Do I need to do something like Mojo.Controller.stageController.popScene("scene2"); in the activate of the scene1?

    Sorry if my question sounds silly, but I am still having problems to get it working and I am wondering what I am doing wrong...

    Thanks again for all your time and help guys
    Vas
  8. #8  
    Nope, the default action for the back gesture is to pop the top scene off the stack. You don't need to code anything extra for this to happen.

    Don't apologise, that's what the dev forum is here for
  9.    #9  
    Quote Originally Posted by joshsharp View Post
    Nope, the default action for the back gesture is to pop the top scene off the stack. You don't need to code anything extra for this to happen.

    Don't apologise, that's what the dev forum is here for

    I am obviously doing something wrong and I cannot see what. Thanks for clarifying this for me, but I am still having the multiple load issue...

    Is there an example in the SDK examples (or online) that you can think of, so I can check my code against?

    Thanks
    Vas
  10. #10  
    I had that happen once... Frustrated the crap out of me. After spending forever trying to figure it out, I realized that I was registering my event handlers in the activate method and not unregistering them in deactivate. So every time I switched to another scene then came back to my main scene my button tap event handler was getting linked to the tap event again, and again and again. First time I pressed the button it triggered once, came back pushed the button again and it triggered twice, then three times and so on.
    danNielson.com - Slalom - twitter - facebook
    A posted thanks dies with the thread. Clicking the button lasts until the admins get bored with this site and throw it in the recycling bin.
  11.    #11  
    Quote Originally Posted by unfairSurprisery View Post
    I had that happen once... Frustrated the crap out of me. After spending forever trying to figure it out, I realized that I was registering my event handlers in the activate method and not unregistering them in deactivate. So every time I switched to another scene then came back to my main scene my button tap event handler was getting linked to the tap event again, and again and again. First time I pressed the button it triggered once, came back pushed the button again and it triggered twice, then three times and so on.
    Would it be ok to pm you 2 scenes to check my code?
    I was hoping that this is what I was doing wrong...but checking again all my event handlers are registered in my setup function. My deactivate and activate just setup the "black" theme by using

    $$('body')[0].addClassName('palm-dark');
    $$('body')[0].removeClassName('palm-default');

    for activate and

    $$('body')[0].addClassName('palm-dark');
    $$('body')[0].removeClassName('palm-default');

    for deactivate...

    Sorry to pester you on what I am sure it will be an easy bug...
    I get these days where my eyes do fool me...

    Thanks
    Vas
  12. #12  
    That would be ok i guess. or you could post them here. Also, you can check the link in my sig for some code you can compare against. Just use 7-zip to open the ipk.
    danNielson.com - Slalom - twitter - facebook
    A posted thanks dies with the thread. Clicking the button lasts until the admins get bored with this site and throw it in the recycling bin.
  13.    #13  
    Here we go....I tried to keep it simple...
    If you would like to see any other file do let me know....

    index.html
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    	<title>Geek Tools</title>
    	<script src="/usr/palm/frameworks/mojo/mojo.jsjsjs&$quot$; $type$=&$quot$;$text$/$javascript$&$quot$; $x$-$mojo$-$version$=&$quot$;$1$&$quot$; /&$gt$;
        &$lt$;$script$ $src$=&$quot$;$app$/$assistants$/$stage$-$assistant$.$js$&$quot$; $type$=&$quot$;$text$/$javascript$&$quot$;&$gt$;&$lt$;/$script$&$gt$;
        &$lt$;$script$ $src$=&$quot$;$app$/$assistants$/$first$-$assistant$.$js$&$quot$; $type$=&$quot$;$text$/$javascript$&$quot$;&$gt$;&$lt$;/$script$&$gt$;
        &$lt$;$script$ $src$=&$quot$;$app$/$assistants$/$second$-$assistant$.$js$&$quot$; $type$=&$quot$;$text$/$javascript$&$quot$;&$gt$;&$lt$;/$script$&$gt$;
    	&$lt$;$script$ $src$=&$quot$;$app$/$assistants$/$third$-$assistant$.$js$&$quot$; $type$=&$quot$;$text$/$javascript$&$quot$;&$gt$;&$lt$;/$script$&$gt$;
    &$lt$;/$head$&$gt$;
    &$lt$;$body$&$gt$;
    	&$lt$;$h2$&$gt$;&$lt$;/$h2$&$gt$;
    	&$lt$;$p$&$gt$;
    
    
    	&$lt$;/$p$&$gt$;
    &$lt$;/$body$&$gt$;
    &$lt$;/$html$&$gt$;
    first-scene.html
    Code:
    <div id="main" class="palm-scene">
    	<div class="palm-header">
    		<div class="palm-header-center" align="center">First Scene</div>
    	</div>
    	<div class="palm-header-spacer"></div>
    		
    	<div x-mojo-element="Button" id="Scene2"></div>
    	<div x-mojo-element="Button" id="Scene3"></div>
    </div>
    first-assistant.jsjsjs
    Code:
    function FirstAssistant() {
    
    }
    
    FirstAssistant.prototype.setup = function() {	
    	this.buttonAttributes = {};
    	
    	// a local object for button model
        this.buttonModel = {
         "buttonClass" : "",
         "disabled" : false
        };
    	
    	// setup menu
    	this.controller.setupWidget(Mojo.Menu.appMenu, { omitDefaultItems: true }, this.menuModel);
    	
      	// set up the buttons
        this.controller.setupWidget("Scene2", {label: "Scene2"}, this.buttonModel); 
    	this.controller.setupWidget("Scene3", {label: "Scene3"}, this.buttonModel); 
    	
      	// bind the buttons to a handler
        Mojo.Event.listen(this.controller.get("Scene2"), Mojo.Event.tap, this.handleButtonPress.bind(this),this.controller.get("Scene2"));
    	Mojo.Event.listen(this.controller.get("Scene3"), Mojo.Event.tap, this.handleButtonPress.bind(this),this.controller.get("Scene3"));
    };
    
    FirstAssistant.prototype.activate = function(event) {
    	$$('body')[0].addClassName('palm-dark');
    	$$('body')[0].removeClassName('palm-default');
    }
    
    FirstAssistant.prototype.handleButtonPress = function(event,controller){
      	// set all our buttons properties
    	Mojo.Event.listen($("Scene2"), "click", this.secondScene.bindAsEventListener(this));
    	Mojo.Event.listen($("Scene3"), "click", this.thirdScene.bindAsEventListener(this));
    };
    
    FirstAssistant.prototype.deactivate = function(event) {
    	$$('body')[0].addClassName('palm-dark');
    	$$('body')[0].removeClassName('palm-default');
    }
    
    FirstAssistant.prototype.cleanup = function(event) {
    
    }
    
    FirstAssistant.prototype.secondScene = function(event){
       Mojo.Controller.stageController.pushScene("second");
    }
    
    FirstAssistant.prototype.thirdScene = function(event){
       Mojo.Controller.stageController.pushScene("third");
    }
    second-scene.html
    Code:
    <div id="main" class="palm-hasheader">
        <div class="palm-header">Second Scene</div>
    </div>
    second-assistand.jsjsjs
    Code:
    function SecondAssistant() {
    
    }
    
    SecondAssistant.prototype.setup = function() {
    
    }
    
    SecondAssistant.prototype.activate = function(event) {
    	$$('body')[0].addClassName('palm-dark');
    	$$('body')[0].removeClassName('palm-default');
    }
    
    SecondAssistant.prototype.deactivate = function(event) {
    	$$('body')[0].removeClassName('palm-dark');
    	$$('body')[0].addClassName('palm-default');
    }
    
    SecondAssistant.prototype.cleanup = function(event) {
    
    }
    third-scene.html
    Code:
    <div id="main" class="palm-hasheader">
        <div class="palm-header">Third Scene</div>
    </div>
    third-assistant.jsjsjs
    Code:
    function ThirdAssistant() {
    
    }
    
    ThirdAssistant.prototype.setup = function() {
    
    }
    
    ThirdAssistant.prototype.activate = function(event) {
      	$$('body')[0].addClassName('palm-dark');
    	$$('body')[0].removeClassName('palm-default');
    }
    
    ThirdAssistant.prototype.deactivate = function(event) {
    	$$('body')[0].removeClassName('palm-dark');
    	$$('body')[0].addClassName('palm-default');
    }
    
    ThirdAssistant.prototype.cleanup = function(event) {
    
    }
    stage-assistant.jsjsjs
    Code:
    function StageAssistant() {
    }
    
    StageAssistant.prototype.setup = function() {
         	this.controller.pushScene({
    		name: "first",
    		disableSceneScroller: true
    	});
    };
  14. #14  
    Code:
        Mojo.Event.listen(this.controller.get("Scene2"), Mojo.Event.tap, this.handleButtonPress.bind(this),this.controller.get("Scene2"));
    	Mojo.Event.listen(this.controller.get("Scene3"), Mojo.Event.tap, this.handleButtonPress.bind(this),this.controller.get("Scene3"));
    };
    FirstAssistant.prototype.handleButtonPress = function(event,controller){
      	// set all our buttons properties
    	Mojo.Event.listen($("Scene2"), "click", this.secondScene.bindAsEventListener(this));
    	Mojo.Event.listen($("Scene3"), "click", this.thirdScene.bindAsEventListener(this));
    };
    Found it.

    Ok, first, let me explain the fourth argument of Mojo.event.listen. Takes either true or false. That's it. And all it does is tell the event handler loop to call the event in the capture phase. In other words, don't wait until all the events have been grabbed before calling the associated functions.

    As to your problem. You're rebinding every time you tap a button.
    So, scratch handleButtonPress and change the two lines in your setup method to:
    Code:
    Mojo.Event.listen("Scene2", Mojo.Event.tap, this.secondScene.bind(this));
    Mojo.Event.listen("Scene3", Mojo.Event.tap, this.thirdScene.bind(this));
    And the first argument can be an id string or an element. and this.controller.get() is synonymous to $()
    danNielson.com - Slalom - twitter - facebook
    A posted thanks dies with the thread. Clicking the button lasts until the admins get bored with this site and throw it in the recycling bin.
  15. #15  
    Sorry, I may the last part of that last post was a bit off,
    change "Scene2" to $("Scene2)... Got a bit confused there, prototype's Event.observe, which Mojo.Event.listen is supposed to be an extension of, can take an id string, but the later can't. Oh, and if you want to make your code more concise, there's a few things you can do. First, instead of doing a full WhateverAssistant.prototype.newfunction every time, you can do:
    Code:
    WhateverAssistant.prototype = {
     setup: function() {
    ...
     },
     function2: function() {
    ...
     },
     function3: function() {
    ...
     }
    }
    And you can roll your pushScene functions into one. like so:
    Code:
    setup: function(){
      Mojo.Event.listen($('scene2button'),Mojo.Event.tap,this.sceneButtonTap.bind(this));
      Mojo.Event.listen($('scene3button'),Mojo.Event.tap,this.sceneButtonTap.bind(this));
    },
    sceneButtonTap: function(event){
      switch(event.element().innerText){
        case 'The Text on Your Scene2 Button':
          Mojo.Controller.stageController.pushScene("second");
          break;
        case 'The Text on Your Scene3 Button':
          Mojo.Controller.stageController.pushScene("third");
          break;
     }
    }
    danNielson.com - Slalom - twitter - facebook
    A posted thanks dies with the thread. Clicking the button lasts until the admins get bored with this site and throw it in the recycling bin.
  16.    #16  
    Quote Originally Posted by unfairSurprisery View Post
    [code]

    Code:
    Mojo.Event.listen("Scene2", Mojo.Event.tap, this.secondScene.bind(this));
    Mojo.Event.listen("Scene3", Mojo.Event.tap, this.thirdScene.bind(this));
    And the first argument can be an id string or an element. and this.controller.get() is synonymous to $()
    This did the trick for me !!!!!
    Thanks a lot !!! I owe you one
    Sorry I din't reply earlyer but I only had time to try it out today, even though I did see your post two days ago.
  17.    #17  
    Quote Originally Posted by unfairSurprisery View Post
    First, instead of doing a full WhateverAssistant.prototype.newfunction every time, you can do:
    Code:
    WhateverAssistant.prototype = {
     setup: function() {
    ...
     },
     function2: function() {
    ...
     },
     function3: function() {
    ...
     }
    }
    Also this is a handy tip to know. I really didn't like the XYZAssistant.prototype.setup = function() paradigm but this is what all the examples I have seen had. I looked up your code and I prefer your style. Many thanks for all your help.

    I'm just about to give your app a try now too
  18. #18  
    cool, headsup though, its got a bug in one of the rendering algorithms that's slowing it down. Haven't had a chance to track it down yet... Just up the difficulty to get a better game speed.

Posting Permissions