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.

Comments
Tink's Gravatar Not just Flex but AS in general including previous versions.
# Posted By Tink | 7/29/08 10:25 AM
Nathan's Gravatar I would call it assignment chaining, but I'm not sure if there's an official definition.

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.
# Posted By Nathan | 7/29/08 12:58 PM
All Content Copyright 2005, 2006, 2007 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.8.