[flexcoders] Re: NaN and Infinity showing in output - How to modify?

2008-07-31 Thread zyzzx00_99
to possibly help in the vague understanding, the ()?: stuff is an
inline if statement.  (mynum  maxval) ?  is like saying If mynum is
greater than maxval.  : is the else.

re your errors: from eyeballing everything, numberformatter.format
returns a string (control click into .format in flexbuilder to see
the framework code).  I could be making this up, but NaN might be a
class too, so it is probably the cause of your coercion error.  I
would break out everything into a function that returns a string (for
the text property of your label), so the last part would be return
PrepForDisplay.format(mynum).toString() (or as String).

Good Luck
Jeremy



--- In flexcoders@yahoogroups.com, Blair Cox [EMAIL PROTECTED] wrote:

 Hi Sid, thanks for the reply. I tried your first solution since I
did not
 create a custom function and it returns;
 
 1067: Implicit coercion of value of type Number to an unrelated type
Class
 
 I have a vague understanding of what is occurring here. Any way
around it?
 How difficult would it be to modify or create a custom function?
 
 What I have now is simply:
 
 mx:NumberFormatter id=PrepForDisplayprecision=2
 rounding=updecimalSeparatorTo=.   
thousandsSeparatorTo=,
 useThousandsSeparator=trueuseNegativeSign=true/
 
 -- 
 Blair Cox
 
 http://www.luminultra.com
  
 
 From: Sid Maskit [EMAIL PROTECTED]
 Reply-To: flexcoders@yahoogroups.com
 Date: Thu, 31 Jul 2008 07:51:38 -0700 (PDT)
 To: flexcoders@yahoogroups.com
 Subject: Re: [flexcoders] NaN and Infinity showing in output - How to
 modify?
 
  
  
 
 If the format function is a custom function you have written, you
could just
 have it check whether you like the result it is about to return, and
if not,
 return something else. If that is not the case, I believe that you
should be
 able to put tests into your binding statement. 
 
 You could test for NaN with something like this:
 
 mx:Label text={(myNumber is NaN) ? 0 : PrepForDispl ay.format(
myNumber)
 }/
 
 I'm not sure about infinity, but I assume that you can test for this by
 looking for the greatest possible value of the number. Assuming that you
 have set up the variable maxValue to contain that value, you should
be able
 to do something like this:
 
 mx:Label text={(myNumber  maxValue) ? 0 : PrepForDispl ay.format(
 myNumber) }/
 
 If you put the two together, it would look something like this:
 
 mx:Label text={(myNumber is NaN) ? 0 : (myNumber  maxValue) ? 0 :
 PrepForDispl ay.format( myNumber) }/
 
  
 Sid Maskit
 Partner 
 CraftySpace
 Better Websites for a Better World
 http://www.CraftySpace.com
 blog: http://smaskit.blogspot.com/





[flexcoders] Re: NaN and Infinity showing in output - How to modify?

2008-07-31 Thread Amy
--- In flexcoders@yahoogroups.com, Sid Maskit [EMAIL PROTECTED] wrote:

 Try something like this:
 
 mx:Label id=display text={(isNaN(myNumber as Number)) ? 0 : 
PrepForDisplay.format(myNumber)} visible={display.text != '0' 
amp;amp; display.text != 'In,fin,ity.00'}/
 
 Note that you need to give the Label component and id, and use that 
id to refer to it in your statements within braces.
 
 By the way, as you are no doubt noticing, the larger point here is 
that braces are not just for binding, but can contain all sorts of 
ActionScript.

The braces actually _are_ executing a binding here, as they will do 
something different when the value of the variable changes.  If the 
value was not expected to change, you could do the same without the 
braces.

HTH;

Amy



Re: [flexcoders] Re: NaN and Infinity showing in output - How to modify?

2008-07-31 Thread Sid Maskit
I think I see your point here, and I guess that I have not made mine clearly 
enough, so here is a little more on this.

When we say text={myNumber}, we are really setting up whatever is within the 
braces as an event handler for the event dispatched whenever myNumber changes. 
If we think of binding as setting up that relationship, then yes, everything in 
this thread is using binding. However, I think it is common for beginners to 
think of that statement as binding the text attribute to the latest value of 
myNumber, and to think of binding as doing no more than such assignments.

I think it is important part of learning flex to realize that one can do much 
more than that. In the largest sense, one can do almost anything that is 
possible with a single ActionScript statement, so long as it returns a valid 
value for the attribute to which it is assigned, in this case the text 
attribute. For example, one could do something rather complicated, like this:

text={(myNumber != 0) ? myFunction() : myOtherFunction()}

So long as both functions returned a value that could be validly assigned to 
the text attribute, this approach is valid, and we can obviously do any valid 
ActionScript within either function. I'm not sure that this approach would be a 
best practice, but the point is that we are doing a lot more than simply taking 
the value of myNumber and assigning it to text.

Finally, although I do not think you meant to imply this, I think it is worth 
saying that one cannot use ActionScript within an assignment to an MXML 
attribute without using braces. Well, one can, but it will be treated as a 
string, not as code to be run.
 Sid Maskit
Partner 
CraftySpace
Better Websites for a Better World
http://www.CraftySpace.com
blog: http://smaskit.blogspot.com/



- Original Message 
From: Amy [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Thursday, July 31, 2008 10:47:30 AM
Subject: [flexcoders] Re: NaN and Infinity showing in output - How to modify?


--- In [EMAIL PROTECTED] ups.com, Sid Maskit [EMAIL PROTECTED]  wrote:

 Try something like this:
 
 mx:Label id=display text={(isNaN( myNumber as Number)) ? 0 : 
PrepForDisplay. format(myNumber) } visible={display. text != '0' 
amp;amp; display.text != 'In,fin,ity. 00'}/
 
 Note that you need to give the Label component and id, and use that 
id to refer to it in your statements within braces.
 
 By the way, as you are no doubt noticing, the larger point here is 
that braces are not just for binding, but can contain all sorts of 
ActionScript.

The braces actually _are_ executing a binding here, as they will do 
something different when the value of the variable changes.  If the 
value was not expected to change, you could do the same without the 
braces.

HTH;

Amy

 


  

[flexcoders] Re: NaN and Infinity showing in output - How to modify?

2008-07-31 Thread Amy
--- In flexcoders@yahoogroups.com, Sid Maskit [EMAIL PROTECTED] wrote:

 I think I see your point here, and I guess that I have not made 
mine clearly enough, so here is a little more on this.
 
 When we say text={myNumber}, we are really setting up whatever is 
within the braces as an event handler for the event dispatched 
whenever myNumber changes. If we think of binding as setting up that 
relationship, then yes, everything in this thread is using binding. 
However, I think it is common for beginners to think of that 
statement as binding the text attribute to the latest value of 
myNumber, and to think of binding as doing no more than such 
assignments.
 
 I think it is important part of learning flex to realize that one 
can do much more than that. In the largest sense, one can do almost 
anything that is possible with a single ActionScript statement, so 
long as it returns a valid value for the attribute to which it is 
assigned, in this case the text attribute. For example, one could do 
something rather complicated, like this:
 
 text={(myNumber != 0) ? myFunction() : myOtherFunction()}
 
 So long as both functions returned a value that could be validly 
assigned to the text attribute, this approach is valid, and we can 
obviously do any valid ActionScript within either function. I'm not 
sure that this approach would be a best practice, but the point is 
that we are doing a lot more than simply taking the value of myNumber 
and assigning it to text.
 
 Finally, although I do not think you meant to imply this, I think 
it is worth saying that one cannot use ActionScript within an 
assignment to an MXML attribute without using braces. Well, one can, 
but it will be treated as a string, not as code to be run.

In at least some instances, MXML will run code that is not within 
braces, for instance 

mx:LinkBar id=chartSwitcher borderStyle=solid 
itemClick=invalidateDisplayList() /

It's not treating the text within the itemClick property as a string, 
but as code to be run.  I'm not certain exactly where the line is, 
but you don't ALWAYS have to enclose your as expressions in brackets 
to get them to run.

-Amy



Re: [flexcoders] Re: NaN and Infinity showing in output - How to modify?

2008-07-31 Thread Sid Maskit
True. Good point. Event handler attributes are assumed to contain code. Most 
attributes are of a type like string or number, and will need braces to get a 
value treated as code. I'm not sure if there are other attributes beside event 
handlers which are also assumed to contain code, but it wouldn't surprise me if 
there are some others.

 Sid Maskit
Partner 
CraftySpace
Better Websites for a Better World
http://www.CraftySpace.com
blog: http://smaskit.blogspot.com/



- Original Message 
From: Amy [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Thursday, July 31, 2008 1:01:13 PM
Subject: [flexcoders] Re: NaN and Infinity showing in output - How to modify?


--- In [EMAIL PROTECTED] ups.com, Sid Maskit [EMAIL PROTECTED]  wrote:

 I think I see your point here, and I guess that I have not made 
mine clearly enough, so here is a little more on this.
 
 When we say text={myNumber} , we are really setting up whatever is 
within the braces as an event handler for the event dispatched 
whenever myNumber changes. If we think of binding as setting up that 
relationship, then yes, everything in this thread is using binding. 
However, I think it is common for beginners to think of that 
statement as binding the text attribute to the latest value of 
myNumber, and to think of binding as doing no more than such 
assignments.
 
 I think it is important part of learning flex to realize that one 
can do much more than that. In the largest sense, one can do almost 
anything that is possible with a single ActionScript statement, so 
long as it returns a valid value for the attribute to which it is 
assigned, in this case the text attribute. For example, one could do 
something rather complicated, like this:
 
 text={(myNumber != 0) ? myFunction() : myOtherFunction( )}
 
 So long as both functions returned a value that could be validly 
assigned to the text attribute, this approach is valid, and we can 
obviously do any valid ActionScript within either function. I'm not 
sure that this approach would be a best practice, but the point is 
that we are doing a lot more than simply taking the value of myNumber 
and assigning it to text.
 
 Finally, although I do not think you meant to imply this, I think 
it is worth saying that one cannot use ActionScript within an 
assignment to an MXML attribute without using braces. Well, one can, 
but it will be treated as a string, not as code to be run.

In at least some instances, MXML will run code that is not within 
braces, for instance 

mx:LinkBar id=chartSwitcher borderStyle= solid 
itemClick=invalida teDisplayList( ) /

It's not treating the text within the itemClick property as a string, 
but as code to be run.  I'm not certain exactly where the line is, 
but you don't ALWAYS have to enclose your as expressions in brackets 
to get them to run.

-Amy