views:

96

answers:

2

I'm trying to learn how to use actionscript over mxml for flexibility. I have this simple block of mxml that I'm trying to convert to actionscript, but I'm stuck half way though

<s:Rect id="theRect" x="0" y="50" width="15%" height="15%">
   <s:fill> 
      <s:SolidColor color="black" alpha="0.9" />
   </s:fill>
</s:Rect>

I can convert the Rect no problem to

private var theRect:Rect = new Rect();
theRect.x = 0;
theRect.y = 50;
theRect.width = "15%";
theRect.height = "15%";

then I'm stuck on the fill. What's the most efficient way to add the SolidColor in as few lines of code as possible.

+1  A: 

This should work:

private var theRect:Rect = new Rect();
theRect.x = 0;
theRect.y = 50;
theRect.width = "15%";
theRect.height = "15%";
theRect.fill = new SolidColor(0x000000, 0.9);

The properties in MXML (<fill>) are just dot properties in Actionscript, and the values are what's next, so it's not too bad.

Hope that helps, Lance

viatropos
no way, that simple? thank you :)
touB
i know, i'm like that too sometimes. no problem.
viatropos
A: 

You could have done that automatically, by using the compiler flag that keeps the generated actionscript files. See this article for how to use it.

bug-a-lot