5 Replies Latest reply on May 26, 2010 10:30 PM by Dajji

    Can I use variables in mxml tags?

    jkintner

      I want to control a lot of details in a layout.  I need to use variables to do this.  Of course I can use AS.  Is there a way to do it in the MXML tags?  See the code below.  I can do the "myLine.x = lineX" in AS.  But is there something like:  x="{lineX}" to use in a tag?  (This gives a warning, though it does work.)  It would make life faster if I could...   Is there a "right" way to do this?

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                     initialize="init()" >
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
                  internal var lineX:Number = 25;
                  private function init():void {
                      myLine.x = lineX + 50;       
                  }
              ]]>
          </fx:Script>
          <s:Line id="myLine" xFrom="0" xTo="0" yFrom="50" yTo="300" >
              <s:stroke>
                  <s:SolidColorStroke color="0x0000ff" weight="2" />
              </s:stroke>
          </s:Line>
          <s:Line id="myOtherLine" x="{lineX}" xFrom="0" xTo="0" yFrom="50" yTo="300" >
              <s:stroke>
                  <s:SolidColorStroke color="0xff0000" weight="2" />
              </s:stroke>
          </s:Line>
      </s:Application>