Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36
  1.    #21  
    All right, I found some time to read your code and cut out everything I understand, so here's some select code I want to know more about if you please could tell me.

    A. At the very first you call this.l1, so how/why do you call it there?
    B. I can tell that greets is an array of sorts, but I've not run into one like it before, how does it work, what is merid?
    C. When you call the zeroFill() function, do you have to put the this. in front? What does that accomplish?
    D. Lastly, how does the greets variable get called by the greeting/merid variable?

    Code:
    this.l1 = this.controller.get("label1");
    
    var greets = [
    	{ merid:		'am',
    		greeting:	"Good Morning!<br/> It's "},
    	{ merid:		'pm',
    		greeting:	"Good Afternoon!<br/> It's "},
    	{ merid:		'pm',
    		greeting:	"Good Evening!<br/> It's "},
    	{ merid:		'pm',
    		greeting:	"Good Night!<br/> It's "}
    ];
    
    	var sec = this.zerofill(date.getSeconds(),2);
    	var frame = 0;
    		
    	if( hour < 12 ){ frame = 0; }
    	else if( hour < 18 ){ frame = 1; }
    	else if( hour < 21 ){ frame = 2; }
    	else { frame = 3; }
    		
    	var merid = greets[frame].merid;
    	var greeting = greets[frame].greeting;
    		
    	this.l1.update(greeting+m+' '+d+', '+y+' - '+hour+':'+min+':'+sec+' '+merid)
    			
    	}
    };
  2. #22  
    Not a problem.

    A) The this.l1... line just caches my reference to the label. You should do that for any element you will be accessing regularly as it can improve performance significantly. Not really necessary in your app but it's good to get in the habit.

    B) Greets is an array of objects. Similar to how I setup MainAssistant.prototype={ setup: function(){},...}, by using curly brackets to denote an object you can just put in parameter: value, parameter2: value2. This is done to make the code later on more readable. I.E. by referencing greets[whichone].greeting to get that particular greeting.

    As to merid, it's short for meridian. am/pm is short for anti-meridian/post-meridian. Meridian in this case being noon.

    C) In my example, zeroFill was created as a method of MainAssistant.prototype. That means that the fully qualified name for zeroFill is actually MainAssistant.prototype.zeroFill. using this.zeroFill simply shortens the code since we are already in the MainAssistant.prototype object. If you want to be able to just call 'zeroFill(...)' then you need to declare the function in the global scope, meaning outside of the MainAssistant.prototype object.

    D) as I said above, greets is an array of objects. frame is just an integer which we use as an index for the greets array. once we have the array item we want( greets[frame] ) we can simply call the desired property, .merid or .greeting in this case.

    For instance, in my example, if the hour is less than 12, then merid = greets[0].merid or the .merid value of the first object in greets, which is 'am'.
    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.    #23  
    Right, I understand all the code now, just a few programming quirks I need explaines.

    Do you have to have a comma or a semi-colon after the curly braces? ( I know you don't need a semi-colon unless there's multiple lines of code on the same line.)

    merid: 'am',
    greeting: ""

    Is the colon in the previous lines similar to an ='s ?
  4. #24  
    when declaring an object initially, you can do it in bulk. basically,

    myobj = {
    somevar: 'somevalue',
    someothervar: 'someothervalue };

    is equivalent to:

    myobj.somevar = 'somevalue';
    myobj.someothervar = 'someothervalue';

    I prefer the first method because it saves me some typing and makes the filesize smaller and, in my opinion, it's easier to read.

    In the first case, the comas are required as you simultaneously setting multiple values on one object. Think of it like setting an array.

    In the second case the semicolons are not required in javascript, but most debuggers will throw a warning if you don't use them. (just click on the jslint button in Ares) The main reasons being
    1 - Most other languages do require the semi-colon to end an instruction and it's just good to keep in the habit of doing so.
    2 - If you minify your code and don't have them then it will break. Minifying javascript is, at its base-level, just removing all white-space that can be removed. Basically,
    Code:
    function SomeFunction( param1, param2) {
        var somevar = 'something';
        for(var x = 0; x<20 ; x++ ){
            somevar = somevar + " " + x;
            someOtherFunction(somevar);
            return somevar;
        }
    }
    becomes
    Code:
    function SomeFunction(param1,param2){var somevar='something';for(varx=0;x<20;x++){somevar=somevar+" "+x;someOtherFunction(somevar);return somevar;}}
    Might not seem like much, but consider doing that to a few hundred or even thousand lines of code. For example, jQuery is 155KB, minified it's only 24KB. That makes a big difference in your bandwidth costs over the course of a few-thousand page views.

    So, you can see where not having the semicolons would cause a problem. Basically, not using them gives you

    Code:
    function SomeFunction(param1,param2){var somevar='something'for(varx=0;x<20;x++){somevar=somevar+" "+xsomeOtherFunction(somevar)return somevar}}
    Which is just gibberish. Some minifiers are smart enough to add the semi-colons in themselves, but not all. And even the ones that are sometimes miss. Then you're stuck trying to track down a single missing semi-colon in a single 5000 character long line of code.

    The real problem though, is that you may not actually have control over whether or not the code gets minified. Some web hosts minify javascript, html and/or css automatically before sending it out to your users so as to save bandwidth. Also, this may not exist any more, but years ago I had a plugin for firefox that minified and gzipped everything in my web cache to make it smaller on my hard-disk. I remember, that at that time there were several pages I had to do a hard refresh(force the browser to redownload the web page and all css/images/scripts instead of using the cached copies - used to be Ctrl+click refresh, now most browsers do it every time you click refresh but not when you hit f5 or ctrl+r) every time I visited them.
    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.
  5.    #25  
    So I presume that you put the comma at the end of functions within the main.prototype for the same reason as the semi-colons at the end of a line of code?

    Also, what's the difference in the use of ' ' and " "

    Final note: I tried my code again, with the <br/> inserted, but as long as I have the "One Line" option selected for the label, it doesn't show the second line. So how can I have the output display in the middle of the label (vertically)? I've been trying this bit of code I found, but it doesn't seem to work. this.l1.verticalAlign="middle"
    Last edited by Zen00; 08/04/2010 at 08:52 AM.
  6. #26  
    First, no. The coma at the end of my methods(a function belonging to an object is called a method, and a variable belonging to an object is called a member) in MainAssistant.prototype are because I'm declaring an object. Remember, think like it's an array. The whole thing is one big command, not 4 little ones.

    Second. In some languages it makes a huge difference. In the above examples the only difference it makes is if I'm declaring a string that contains an apostrophe like "don't" vs 'don\'t'. Generally, encase the string in whatever type of quotes your string contains less of so you don't have to escape as much. In most languages, however, one or the other will be 'simple' and the other 'complex'. For instance, in PHP you can use variables directly in a "" string but not a '' string like this: "Hello, The Time is $time" and the variable($time) will automatically be converted into the time it refers to.

    If your label is the default size, then it perfectly fits two lines of text. Which is what we have. Just drop the oneline setting. If you've made it bigger, then you have two options. You can go back to the first page and use the solution I posted before to center your text, or you can grab an absolute box(middle-right under layout - the one with the red arrows), make it the size you want then put your label inside of it and shrink your label down to size then change the 'verticalAlign' property for your label to 'center'.
    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.    #27  
    Just tried implementing your vertical align method, unfortunately it didn't work.

    So, just to make sure we're on the same page, I'm posting a screen shot of what I have. Left is what I have, right is what I want.

  8. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #28  
    To center in the window, you'll need to play some tricks. I recommend you put a border around your displayDate div so that you'll understand exactly what's going on (add a class and use CSS). There's not a single "right" way to do it, depending on what other things you'll need to do. For example, you can use CSS to absolutely position the div, but then it only works for you if you keep that div the same height and don't mind it only working on the Pre's screen (as opposed to the Pixi's screen). To nicely center it at all times, you could use HTML tables (put your displayDate div into the middle cell of a 3x3 table and force the table's height) or you could use multiple div's whose purpose isn't to hold content but to help push around the displayDate div.

    You can read up a little here:
    Vertical Centering in CSS
  9. #29  
    Ok, it works for me. Here's how I did it, with screenshots.

    step1.png - STEP-1) Clear away everything except your button. Don't touch the code, just kill all your panels and the label. This is important as ares has some glitches that can cause old settings line 'oneline' to stay on.

    step2-3.png
    -STEP-2) Drag an ABSOLUTE PANEL over to your scene.
    -STEP-3) With the ABSOLUTE PANEL still selected, click Maximize.

    step456.png
    --NOTE:layontKind must be 'absolute' 'vbox' or 'hbox' will not work.
    -STEP-4) Drag a LABEL into your newly created ABSOLUTE PANEL. It will just land wherever you drop it.
    -STEP-5) With your new LABEL still selected click the X-maximize button. This will get your label positioned horizontally.(not the text though. that's later)
    -STEP-6) Again, with your LABEL still selected, then open up the 'Geometry' view and set verticalAlign to 'center'.

    step7.png
    -STEP-7) Set the name of your LABEL to whatever you had your old one set to.

    step8.png
    -STEP-8) Finally, pop over to the style tab and click the 'center-text' button.

    And that's it.
    Attached Images Attached Images
    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.
  10. #30  
    It looks like you may have a working solution, however I wanted to make you aware of the Ares way of doing things. I very briefly covered this in my short Intro to Ares blogicle. Because I don't have 10 posts, I can't post the link, see my profile and check my blog.

    Basically, in Ares if you have a label, say label1 you can do:
    Code:
    this.$.label1.setLabel("Hello World");
    var text = this.$.label1.getLabel();
    This style, at least for me is a bit more elegant
  11. #31  
    Yeah, I've seen that style... I honestly can't say that I like it though... I guess it's just a matter of opinion. Personally, I don't like Ares, and I much prefer to use the base Prototype methods over the Mojo extensions... like $('mylabel).update('Hello World'); or $$('div#.palm-button.myclass').each(...dothumbthing...). Unfortunately, the Ares way of setting up widgets makes it much more difficult to use Prototype as it just doesn't setup elements the same.
    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.    #32  
    All right, your absolute box trick worked, though it's not as clean as I would like (it would still be nice to easily set the label to vertical align its contents, why you can't I don't know!), but anyways, it worked out.

    I updated my code with a few more comments and semicolons on all the correct lines. I'll keep your code in mind for when I cover arrays, as it is a much better way to do this in the end.

    Now the next thing to do would be to get a mechanical voice to say "At the sound of the tone, the time will be...", which would be interesting to get working.
  13. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #33  
    If you add the border to your original label, you'll probably see that it did "vertical align" it properly - the box just happens to be the exact height of your text ...
  14. #34  
    Text can't vertical align in an element. It's an annoying limitation of HTML. There's a million and two ways to work around it, but the solution I posted seemed easiest... You could also just make your label then initialize it with something like:
    Code:
      this.controller.get('mylabel') or this.$.mylabel
        .update('<div style="vertical-align:middle;">'+$(id).innerText+'</div>');
    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.    #35  
    In direction to my previous question. What does webOS do towards text-to-speech? How would I set it up?
  16. #36  
    Only T2S thing I know of for WebOS is this: http://forums.precentral.net/web-os-...xt-speech.html
    Which only works for homebrew users...
    You could try chopping up audio bits and piecing it together yourself using the Audio API, but I don't know how well that would work...
    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.
Page 2 of 2 FirstFirst 12

Posting Permissions