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

 


      

Reply via email to