Results 1 to 5 of 5
  1.    #1  
    OK for the life of me, I can't figure this out...

    I have two scenes that have access to the same variables, the fist scene calls the second scene and both scenes use the Mojo.Menu.appMenu succesfully which calls the "handleCommand" from the stage-assistant. I am trying to add Mojo.Menu.commandMenu items to both scenes. For some reason, it works in the second scene but not in the first. I even copied the code from the second scene and replaced the code in the first and it still won't fire. The menue items show up properly, but when you click on one of the menu items, all that happens is the item turns blue until you stop pressing on it. The code I am using in both scenes is...


    in "BeerListViewAssistant.prototype.setup = function()" I have....

    this.beerMenuModel = {
    items: [
    {items: []},
    {},
    {},
    {},
    {icon: "send", command: "do-shareBeer"}
    ]};

    if (this.beerIndex > 0) {
    this.beerMenuModel.items[0].items.push({
    icon: "back",
    command: "do-viewPrevious"
    });
    } else {
    this.beerMenuModel.items[0].items.push({
    icon: "",
    command: "",
    label: " "
    });
    };
    if (this.beerIndex < this.beerL.list.length-1) {
    this.beerMenuModel.items[0].items.push({
    icon: "forward",
    command: "do-viewNext"
    });
    } else {
    this.beerMenuModel.items[0].items.push({
    icon: "",
    command: "",
    label: " "
    });
    };

    this.controller.setupWidget(Mojo.Menu.commandMenu, undefined, this.beerMenuModel);
    Then I have the following functions at the end...
    BeerViewAssistant.prototype.shareHandler = function(command) {
    switch(command) {
    case "do-emailStory": this.controller.serviceRequest("palm://com.palm.applicationManager", {
    method: "open",
    parameters: {
    id: "com.palm.app.email",
    params: {
    summary: "#" + this.beerL.list[this.beerIndex].ID + " - " +
    this.beerL.list[this.beerIndex].title,
    text: "#" + this.beerL.list[this.beerIndex].ID + " " +
    this.beerL.list[this.beerIndex].title +
    " Style: " + this.beerL.list[this.beerIndex].style +
    " Container: " + this.beerL.list[this.beerIndex].container +
    " Description: " + this.beerL.list[this.beerIndex].desc1
    }
    }
    });
    break;
    case "do-messageStory":
    this.controller.serviceRequest("palm://com.palm.applicationManager", {
    method: "open",
    parameters: {
    id: "com.palm.app.messaging",
    params: {
    // ** These next two lines are wrapped for book formatting only **
    messageText: "#" + this.beerL.list[this.beerIndex].ID + " " +
    this.beerL.list[this.beerIndex].title + ", " +
    this.beerL.list[this.beerIndex].style + ", " +
    this.beerL.list[this.beerIndex].container
    }
    }
    });
    break;
    }
    };

    BeerViewAssistant.prototype.handleCommand = function(event) {
    if(event.type == Mojo.Event.command) {
    switch(event.command) {
    case "do-viewNext":
    Mojo.Controller.stageController.swapScene(
    {
    transition: Mojo.Transition.crossFade,
    name: "beerView"
    },
    this.beerL, this.beerIndex+1);
    break;
    case "do-viewPrevious":
    Mojo.Controller.stageController.swapScene(
    {
    transition: Mojo.Transition.crossFade,
    name: "beerView"
    },
    this.beerL, this.beerIndex-1);
    break;
    case "do-shareBeer":
    var myEvent = event;
    var findPlace = myEvent.originalEvent.target;
    this.controller.popupSubmenu({
    onChoose: this.shareHandler,
    placeNear: findPlace,
    items: [
    {label: "Email", command: "do-emailStory"},
    {label: "SMS/IM", command: "do-messageStory"}
    ]
    });
    break;
    }
    }
    };
    Is there any reason this shouldn't work in the first scene, but does in second? Again... First scene calls the second, so it has access to all the same variables.
  2. #2  
    Quote Originally Posted by sinime View Post
    Is there any reason this shouldn't work in the first scene, but does in second? Again... First scene calls the second, so it has access to all the same variables.
    When you're referring to the "same variables", are you referring to variables like "this.beerL"? If "this.beerL" is set in the first scene, this data would not be available to the second scene. The only way to make it available would be to pass a reference to the "this" object of the first scene to the second scene when doing the pushScene. Then you could save that reference in another object like "firstscene_assistant" and then in your code you would use "firstscene_assistant.beerL" instead of "this.beerL".
  3.    #3  
    Quote Originally Posted by DanPLC View Post
    When you're referring to the "same variables", are you referring to variables like "this.beerL"? If "this.beerL" is set in the first scene, this data would not be available to the second scene. The only way to make it available would be to pass a reference to the "this" object of the first scene to the second scene when doing the pushScene. Then you could save that reference in another object like "firstscene_assistant" and then in your code you would use "firstscene_assistant.beerL" instead of "this.beerL".
    I am passing the variable with pushScene("beerView", this.beerL, this.beerIndex+1); so once the passed variables get to the second scene, internally they have the same name...

    function BeerViewAssistant(passedBeerList, passedBeerIndex) {
    this.beerL = passedBeerList;
    this.beerIndex = passedBeerIndex;
    }
    The commandMenu works great once the scene comes up to show a single beer with all of its details. Itís the previous scene that I am having issues with getting the commandMenu to work.
  4. #4  
    Have you put in a Mojo.Log.info statement into the handleCommand routine to verify it really isn't getting in the routine?

    I noticed that you have this line in there:

    Code:
    onChoose: this.shareHandler
    If you replace it with this, it'll guarantee that the "this" object is accessible within the shareHandler routine:

    Code:
    onChoose: this.shareHandler.bind(this)
    I wonder if maybe you're getting in handleCommand, but the shareHandler routine is coming up with an exception. Do you see any exceptions in your log?
  5.    #5  
    Quote Originally Posted by DanPLC View Post
    Have you put in a Mojo.Log.info statement into the handleCommand routine to verify it really isn't getting in the routine?

    I noticed that you have this line in there:

    Code:
    onChoose: this.shareHandler
    If you replace it with this, it'll guarantee that the "this" object is accessible within the shareHandler routine:

    Code:
    onChoose: this.shareHandler.bind(this)
    I wonder if maybe you're getting in handleCommand, but the shareHandler routine is coming up with an exception. Do you see any exceptions in your log?
    I'll check that out tonight when I get home... adding a Mojo.Log.info statement and updating the code with your suggestions.

Posting Permissions