4 Replies Latest reply on Nov 25, 2007 11:11 PM by jdhenry

    Runtime Values

    jdhenry
      Hi All,

      I'm trying to assign certain values to certain properties of components at run time, but I'm having trouble. I would like to assign values that include percentages (i. e. button.width ="80%") and values that are bindable (i.e. list.dataProvider = "{someArrayCollection}"). This works fine when working in mxml, but it doesn't work in action script. Any Ideas?

      Thanks,
      -John
        • 1. Re: Runtime Values
          atta707 Level 2
          mxml compiler is doing somethings for you in the background; for example parsing 80% "width" property percentWidth (or was it widthPercent):

          so try button.percentWidth = 80;
          list.dataProvider = someArrayCollection;

          ATTA
          • 2. Re: Runtime Values
            jdhenry Level 1
            Wow Atta. Seems like you're my flex-saviour tonight. I wasn't aware of the "percentWidth" property. So that problem's out of the way.

            As for my problem assigning bindable variables, I made a mistake in my example. I should have specified something more like:

            someComponent.data = {someList.selectedItem}

            In this case, i want to make it so that every time the someList.selectedItem changes, so does someComponent.data. I guess I could set up some sort of cumbersome event listener mechanism, but I just thought I'd ask because it's so easy in mxml.

            <someComponent data="{someList.selectedItem}" />

            But i guess it's like you said, the mxml compiler is doing something in the background.

            Thanks Again,
            John
            • 3. Re: Runtime Values
              atta707 Level 2
              Have you actually tried

              <someComponent id="sc" />

              sc.data = someList.selectedItem?

              I ask this because I *think* -- that is i'm not sure -- that selectedItem property is Bindable by default and sc.data = someList.selectedItem should see the changes in the selected item property.

              Otherwise, as you said, just use an event. And it does have to be cumbersome. As a matter of fact, it won't. Just listen for itemClick event of the list and assign the selected item to the custom component's data property.

              Hope this helps! (I don't have an editor open to try this)

              ATTA
              • 4. Re: Runtime Values
                jdhenry Level 1
                Yeah, I tried that. Didn't work, :(. I just went ahead and did the event listener thing. It wasn't too cumbersome, just not as elegant as I would like. Oh well.

                Thanks,
                -John