Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1.    #1  
    Hey guys,

    Got a quick question for you developers out there. I'm in the process of developing a specific application and need some information on some code to use for a certain scene. In the scene I currently have about 10 text boxes to enter numbers into (we'll say txtBox1, txtBox2, txtBox3 for the example) that I want to get from the scene that they are being entered in to the scene that is going to calculate those numbers.

    I'm developing this in Ares and am having an issue getting those text inputs from that first scene to the second scene. Do any of you know what code will get those values passed from scene to scene? Let's say the first scene is called scn_values and the scene I want to get them to is called scn_results.

    Any help would be greatly appreciated!

    Ricky
  2. #2  
    It depends. If you are just pushing your new scene on top of the old one(you can swipe the back gesture to go back to your text boxes), then you can access them like so, replacing names as necessary.

    Code:
    SecondAssistant.prototype.whateveryourfunctioniscalled = function(){
      dosomethingwith(FirstAssistant.prototype.yourtextfieldmodel.value);
      var sum = FirstAssistant.prototype.yourtextfieldmodel.value+FirstAssistant.prototype.yourothertextfieldmodel.value;
      etc...
    }
    You can also pass variables to your scene assistant when you push it. Like so:
    Code:
    this.controller.stageController.pushScene({name:'myotherscene,variable1:'somevalue',anothervariable:'someothervalue'});
    These values will then be available in the function declaration at the top of your scene assistant. The one that looks like 'function MainAssistant(argFromPusher){}'. Basically, you'll be able to do something like:
    Code:
    function MainAssistant(args){
      Object.extend(this,args);
    }
    That will map the data you passed via pushScene to your current assistant object. In other words. if you passed ...pushScene({name:'two',myarg:'chicken',myotherarg:'caffeine'});
    then using the above, from your twoAssistant you would be able to call this.myarg to get 'chicken' or this.myotherarg to get 'caffeine'.

    At any rate, I hope that wasn't too confusing. If there's anything you don't understand, just ask.
    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.
  3.    #3  
    Thanks a ton! I'll definitely give those a shot when I get home from the office today. The one thing that I see that I may need to have clarified just a little bit is...say I want to push the variables while also pushing the scene, how would I set it so that the variable is a value from one of the text fields? Would it look like this:

    Code:
    ...pushScene({name:'otherscene',variable1:txtBox1.value,variable2:txtBox2.value});
    Does that look right?
  4.    #4  
    Alright, so I gave both methods a shot and I think I'm completely lost... Using these scene names and text box names, could you possibly elaborate on what the code would actually look like?

    Scenes:
    - First scene (formulaEstimation)
    - Second scene (formulaResults)

    Text boxes in formulaEstimation scene:
    - txtBox1
    - txtBox2
    - txtBox3

    I tried substituting multiple ways throughout the samples you provided and each time I click the "Calculate Formula" button, it is either unresponsive or the next scene is completely blank. Sorry to be such a pain and a total n00b at this, but I'm doing all the reading I can and still...no luck.

    Thanks a bunch for any insight you can provide!
  5. #5  
    I pass args to new scenes all the time (though I didn't know about Object.extend... thanks for that). It's as simple as passing them to a different function.


    Once you get the value of the textfield (I assume that isn't an issue, use the example above to do it) you just pass it to the next scene as an argument.

    Mojo.Controller.stageController.pushScene("main", textfieldvalue);
    Then in the declaration of the main scene you take that in as an arg:

    function MainAssistant(textfieldvalue) {
    this.textvalue = textfieldvalue;
    }
    Now you can do stuff with this.textvalue in your new scene.
  6. #6  
    @jason.o Object.extend is part of Prototype's attempt to give javascript more a legitimate class system prior to the massive improvements coming down the pipe in JavaScript2. You should check out the Prototype documentation on Class and Object for more information on that. Basically, it eliminates the awkwardness of the whole 'make a function then turn it into an object' thing we've got going on with JSJSJS $right$ $now$.

    @UndeadCircus - Sorry, I wrote that out the way it says on the palm developer site... This works

    FirstAssistant
    Code:
    FirstAssistant.prototype = {
       ...
      yourButtonTapHandler: function() {
        this.controller.stageController.pushScene('second',{text1:this.txtfield1.value,text2:this.txtfield2.value,text3:this.txtfield3.value});
      },
       ...
    };
    SecondAssistant
    Code:
    function SecondAssistant(argFromPusher) {
    	Object.extend(this,argFromPusher);
    }
    
    SecondAssistant.prototype = {
    	setup: function() {
    		Ares.setupSceneAssistant(this);
    		this.controller.get('label1').update(this.text1);
    		this.controller.get('label2').update(this.text2);
    		this.controller.get('label3').update(this.text3);
    		//this.controller.get('label4').update(this.text1+this.text2+this.text3);//this will concatenate the values I.E. if text1=1,text2=2,text3=3 then the above label4 would be 123.
    		//this.controller.get('label4).update(parseInt(this.text1)+parseInt(this.text2)+parseInt(this.text3)); //this will correctly add your numbers but only works for whole integers(i.e 2)
    		this.controller.get('label4).update(parseFloat(this.text1)+parseFloat(this.text2)+parseFloat(this.text3)); //this is the line I left uncommented because it works the most universally. It accepts any decimal number including floating-point numbers(i.e. 14.546)
    	},
       ...
    };
    oh, and about the this.txtfield stuff. That's not what I named my text fields. You have to set the model name for your textfield. In ares, switch to design view, select your text field, then go over to the right-hand tool bar and in the MODEL section put something in modelName. That is what you'll use to access your value... For instance if you but 'purplebubblegum' in there, then to get the value of that text field you'd call 'this.purplebubblegum.value'. Note, that modelName's must be unique and can contain lower and upper-case letters, numbers and underscores.
    Last edited by unfairSurprisery; 08/10/2010 at 02:16 PM. Reason: forgot something
    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.
  7. #7  
    If you really want to do this right, you should consider creating a class that contains the various data as properties. You can then instantiate an instance of the class in a global scope which can be accessed and written to by all your scenes. Your class can also contain methods(functions) that can be used by all your scenes.

    Passing a bunch of parameters back and forth between scenes is a poor way to handle this.

    I'd recommend that you read the following.

    Prototype JavaScript framework: Defining classes and inheritance

    Prototype JavaScript framework: Class.create
  8. #8  
    Quote Originally Posted by Blubble View Post
    Passing a bunch of parameters back and forth between scenes is a poor way to handle this.
    I tend to agree. I usually use similar methods to those you described. However I also usually don't use Ares since it complicates things. Biggest problem in this case is that you have to manually give each text field value to the global object in the method that sends you to the next scene or setup a propertyChange event for each text field since Ares doesn't let you assign your models to anything other than <CurrentScene>Assistant.<ModelName> or rather, you put the model name you want into a little text box named 'modelName' and Ares assigns your widget model via 'this[modelName]'... One of the many reasons I believe Ares to still only be beta quality software... It hides way to much from the developer and breaks like half of Prototype. For instance, you can't use $() with Ares.

    At any rate, passing data directly to the scene works fine in this case since it is temporary data that is only needed to pass one way.
    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.
  9. #9  
    There are still good reasons to pass data to a subsequent scene. As discussed you can pass multiple parameters, but if you do need to send multiple parameters, I'd suggest putting them into an object, so you can add and subtract properties as you need and you won't have to worry about their order.
  10.    #10  
    Lots of solid information going on here. Definitely appreciate all of your input! I'll do some more reading and see what I can't push out.. Too bad you can't develop in PHP/MySQL. I'd have this stuff already hammered out. Javascript is pretty serious business haha.
  11. #11  
    @appsotutely, My examples above put the data into an object. That said, aside from the aforementioned gripe about Ares making things difficult, the only reason I can think of to pass the data to the new scene instead of using a global operator or just referencing it directly, would be to keep the data private. A feat which is made all too awkward by JavaScript's super-fun prototype based class implementation.

    @UndeadCircus, Yeah, I keep wanting to use Python... Here's to hoping Palm follows suit with desktop Linux and starts installing python standard with WebOS.
    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.
  12. #12  
    Oh, I missed that you're developing in Ares. Since this seems like a simple app and you're learning, do yourself a favor. Ditch Ares. Canned autogenerated code may be seemingly easier up front, but you pay for it later. It ends up tying you down and limiting your flexibility. Canned code always screws you in the end.

    You'll learn more doing coding "by hand". Plus, you'll keep your options open should you want to expand your app. Trust me, you'll thank yourself for learning how to do the heavy lifting yourself. It'll take longer up front, but you will have a deeper understanding for when you want to do more complex apps. You won't learn anything worthwhile using Ares.
    Last edited by Blubble; 08/11/2010 at 12:40 AM.
  13. #13  
    @unfairSurprisery,

    FYI. Be careful with $() notation and some of the other Prototype shortcuts. It works fine in a standard app, but it will leave you hanging if you ever have to convert an app to multi-stage as it doesn't work properly in that kind of app. Just a word of warning.
  14.    #14  
    Quote Originally Posted by Blubble View Post
    Oh, I missed that you're developing in Ares. Since this seems like a simple app and you're learning, do yourself a favor. Ditch Ares. Canned autogenerated code may be seemingly easier up front, but you pay for it later. It ends up tying you down and limiting your flexibility. Canned code always screws you in the end.

    You'll learn more doing coding "by hand". Plus, you'll keep your options open should you want to expand your app. Trust me, you'll thank yourself for learning how to do the heavy lifting yourself. It'll take longer up front, but you will have a deeper understanding for when you want to do more complex apps. You won't learn anything worthwhile using Ares.
    Hahaha. You know I was thinking the same thing when getting into Ares...thinking it was resembling one of those "too good to be true" scenarios. I appreciate the feedback though. I already have Eclipse installed along with all of the other goodies that Palm has available for developers and I actually plan on trying the hand-coded way. Just need to jump in and see how difficult it's actually going to be..
  15. #15  
    You won't regret it. If you're already doing stuff with PHP/MySQL, you've got a head start. You also have a great community here that will always be there to help.
  16.    #16  
    Yea, I've been a web developer for about 7 years now doing web projects involving PHP/MySQL. So I've got a pretty good grasp on how web projects are supposed to flow...I just need to learn how javascript wants to flow. :P
  17. #17  
    If you like programming books, this is my all time favorite JSJSJS $book$.

    JavaScript: The Definitive Guide, Fifth Edition - O'Reilly Media

    Also, I posted a bunch of great resources for new WebOS devs on the NaNplayer Facebook page. The link is in my signature.
  18. #18  
    Quote Originally Posted by Blubble View Post
    FYI. Be careful with $() notation and some of the other Prototype shortcuts. It works fine in a standard app, but it will leave you hanging if you ever have to convert an app to multi-stage as it doesn't work properly in that kind of app. Just a word of warning.
    Any chance you could clarify that statement a bit? Not totally sure I get where you're coming from there. $() just runs document.getElementById() and then extends the returned element with the relevant Prototype extensions. How exactly could that get messed up by converting an app to multi-stage? I'd really like to know that since I'm actually just starting a multi-stage app.

    @UndeadCircus - If you make the switch to eclipse, I highly recommend using Aptana(available as a standalone installer or an eclipse plugin). It adds a few web-related goodies to the mix.
    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.
  19. #19  
    I ran into the $() issue when I converted to multi-stage. In Mitch Allen's Palm webOS book, in the Background Applications (chapter 10), it specifies that "there is no support for Prototype's $() function". If you study any of the open source multi-stage applications, you'll notice that none of them use $(), and I could never understand why until I converted to multi-stage.
  20. #20  
    Remember that document is really window.document. Since it's contained by the window element, it gets all messed up when you have a multi stage app.

    You'll need to use
    Code:
    this.controller.get('btnNext')
    instead.

    Check out the multi-stage section of the stage guidelines.

    The Basics: Stages €“ Palm Developer Center



    You'll also need to use the following syntax for setting event listeners as the Prototype syntax for this doesn't work either.

    Code:
    Mojo.Event.listen(this.controller.get('btnNext'), Mojo.Event.tap, this.onTap_btnNextHandler);



    One other thing to note is that I pre-cached the handler.

    This is very important to avoid memory leaks. In the constructor for your scene assistant, you should precache any event handlers you plan to assign in the assistant.

    Code:
    function PlayAssistant()
    {
       
       this.onClick_btnNextHandler = this.onClick_btnNext.bind(this);
    
    }
    Then, you can use the this.onTap_btnNextHandler object as I have in the event listener above.

    This is a best practice that you should always follow. It helps make sure that you don't create multiple instance of the same function and it forces the correct instance to be unloaded when you stopListening, thereby avoiding a memory leak.



    .
    Last edited by Blubble; 08/11/2010 at 09:31 AM.
Page 1 of 2 12 LastLast

Posting Permissions