4 Replies Latest reply on Mar 17, 2011 3:51 PM by jordana309-36

    [DataBinding] Problem after state change


      I need explanation about databinding mechanism.

      First I have a very simple application (test.mxml)

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">
      <mx:Script source="test.as"/>
      <mx:State name="otherState">
      <mx:AddChild relativeTo="{form1}" position="lastChild">
      <mx:FormItem label="Label">
      <mx:TextInput text="{bindedValue}"/>
      <mx:XMLList id="dp1">

      <mx:Form width="100%" id="form1">
      <mx:FormItem label="ComboBox">
      <mx:ComboBox dataProvider="{dp1}" change="changeState()"/>


      Next I have a very simple ActionScript file (test.as)

      import mx.controls.Alert;

      public var bindedValue:String = "default";

      public function changeState():void{
      if (currentState!="otherState"){
      bindedValue = "otherStateValue";
      Alert.show("Flag rechead ! \n (bindedValue should have been setted at 'otherStateValue')");
      } else {

      Ok now,

      launch the application, and simply change state by click on Item2 on the ComboBox ...
      You pass in the "changeState" function which do
      bindedValue = "otherStateValue";

      2:: Manually change the textInput value by "test" for example

      3:: Come back to the initial state clicking on Item1 on the ComboBox.

      4:: AND next come back to the "otherState" clicking on Item2 ...
      You should do bindedValue = "otherStateValue";,

      But in the textInput you still have "test", don't you ????

      So please could you help me to resolve this ? I can't anderstand why that doesn't work ?

        • 1. Re: [DataBinding] Problem after state change
          Tibetoine Level 1
          This is very strange, please help me ... An expert could have a look on that ?
          • 2. Re: [DataBinding] Problem after state change

            I'm having a very similar problem, and rather than create a brand new post I'll just comment in this one.


            I have a program in which the .mxml main application file needs to be touched by many people who are not programmers to design various versions of a video player that can be distributed. The problem is I need to get all variables in a very "doesn't know how to code at all" way, so I'm asking them to give the a project folder (which is inbedded in a projects folder) and the file names (the files are located inside of projects/projectFolder/assets and projects/projectFolder/videos, and in order to keep the linked association, I have the source for the background image a data binding to a string variable: source="{projectFolder}assets/userTypedNameHere", and the buttons I change the paths used in a custom component for each state (up, down, active, and disabled). These have worked perfectly until I added the project thing.


            I had to rebuild the paths to include the project folder during a preinit() function run on application initialize. The code for that reads:



            projectFolder = "projects/" + projectfolder;

            // The backgroundImg.source would change to a broken image before I got to creation complete, so in preinit I had to grab the value:

            // backgroundImgSource:String declaired outside of any function above preinit

            backgroundImgSource = projectFolder + "/assets/" + String(backgroundImg.source);



            Then, on application creationComplete, I call init(), in which I have this line of code:



            backgroundImg.source = backgroundImgSource;



            And it works just fine. But, for some odd reason, when that exact same thing was built in the preinit() function, I still got a broken image link.


            To make things weirder, I have several buttons in which I try to do the same thing. I don't know the number of buttons that I will have before hand, so I gather them into an array, and loop through the array changing the path. It works when I run it in Flash Builder with the following line:



            /* the button has paths for an image in each state, with reads source.stateName="{stateButtonPath}" */

            btn[i].upButtonPath = projectFolder + "/assets/" + btn[i].upButtonPath;

            /* the upButtonPath is entered by the designer, and is not the source for the button. It is instead a public String in that component, so it will not be forcibly reset by AIR or Flex */

            btn[i].downButtonPath = projectfolder + "/assets/" + btn[i].downButtonPath;

            // and so on through the other two paths



            But, when I distribute this as a release build, this code fails to work. I cannot figure it out. Ideas? This will probably help us both...

            • 3. Re: [DataBinding] Problem after state change
              jordana309-36 Level 1

              Ok...silly. I found my problem. The paths were being passed to a skin file, which was taking the variables before they were changed. Is there anything I can to to make this not happen until after it loads to a certain point? Currently, I have a timer with waits 1 second before pulling in all the variables, but I don't like that option. For one, it's messy, two, it's unsure, and three, it's not the best. Ideas?

              • 4. Re: [DataBinding] Problem after state change
                jordana309-36 Level 1

                I'm sorry, Tibetoine, I solved the problem that you were having back in 2007 by creating protected variable, moving the value into that, and then resetting my bindable variable equal to that value after the state change. That seemed to work.