4 Replies Latest reply on Aug 24, 2007 5:08 AM by Newsgroup_User

    Binding in ActionScript

    Level 7
      I want to do something like you can do in MXML like this:

      <mx:Text text="Page {mainFramework.selectedIndex +1} of
      {mainFramework.numChildren}"/>

      Which shows in the text field Page 1 of 6 (for example)

      but I want to do this in ActionScript.

      I have the following in a creationComplete handler for a text field:

      BindingUtils.bindProperty(this,"text",framework,"selectedIndex");

      Which works in that the selectedIndex of the ViewStack is displayed, but
      I want to add 1 to it and format it as per the MXML example. currently
      I just get 0 displayed where I want Page 1 of 6 (for example)

      Any takers?

      Thanks

      Mark
        • 1. Re: Binding in ActionScript
          Archades
          Does this help? Or is your problem more with getting the VeiwStack data?

          var t:Text = new Text();
          var idx:int = mainFramework.selectedIndex + 1;
          t.text = "Page " + idx + " of " + mainFramework.numChildren; // It might not hurt to use toString()
          • 2. Re: Binding in ActionScript
            Level 7
            Archades wrote:
            > Does this help? Or is your problem more with getting the VeiwStack data?
            >
            > var t:Text = new Text();
            > var idx:int = mainFramework.selectedIndex + 1;
            > t.text = "Page " + idx + " of " + mainFramework.numChildren; // It might not
            > hurt to use toString()
            >


            It's a problem of binding. I want to bind to the selectedIndex of the
            ViewStack, so that when a different child is selected the text field is
            updated. I can do this, but I want to also manipulate the data (by
            adding one to make it for human friendly) and adding the text in there also.

            Mark
            • 3. Re: Binding in ActionScript
              DominicV Level 1
              Hi Mark,

              I've only been using Flex or a few days so I'm a bit of a newbie to it! But I believe this should work...

              {
              ...
              BindingUtils.bindSetter(watcherListener, framework, "selectedIndex", true);
              }

              // Event listener when binding occurs.
              public function watcherListener(object:*):void {
              an_object.text = "Page " + object.toString() + " of 6";
              }

              This worked for me when doing an async webservice call and needing to watch for when a variable changed and bind to it.

              • 4. Re: Binding in ActionScript
                Level 7
                DominicV wrote:
                > Hi Mark,
                >
                > I've only been using Flex or a few days so I'm a bit of a newbie to it! But I
                > believe this should work...
                >
                > {
                > ...
                > BindingUtils.bindSetter(watcherListener, framework, "selectedIndex", true);
                > }
                >
                > // Event listener when binding occurs.
                > public function watcherListener(object:*):void {
                > an_object.text = "Page " + object.toString() + " of 6";
                > }
                >
                > This worked for me when doing an async webservice call and needing to watch
                > for when a variable changed and bind to it.
                >
                >
                >


                Thanks for the reply...That is very close and I managed to do what I
                wanted based on your response.

                Thanks again.

                Mark