Cascading Assignment in ActionScript 3
Did you know you can do cascading assignments in Flex? I had no idea myself. What is a cascading assignment, you ask? Let me attempt to explain.
I came across this line of code in the Flex documentation today:
measuredWidth = measuredMinWidth = lineMetrics.width + 10;
"Huh?" thinks Jeff. How does that work? What is going on here.
Basically, this is short hand. It is the structural equivalent of this:
measuredMinWidth = lineMetrics.width + 10;
measuredWidth = lineMetrics.width + 10;
The code is just simplified so that their are two assignments on one line. I call it a cascading assignment, but have no idea if there is an official name. I didn't do any testing against this, so am unsure if you can have more than two.
Code without a swf link; Doug would grade this post an F. I'm very busy, sorry for letting my blog posts slide.





I should also mention that it's functionally equivalent to:
measuredMinWidth = lineMetrics.width + 10;
measuredWidth = measuredMinWidth;
ActionScript would only do the addition once, assign, returns the value after assignment and then assigns again.