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 R开发者_开发问答ect 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.
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
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.
精彩评论