9 Replies Latest reply on Jan 28, 2011 7:49 AM by Claudiu Ursica

    Object assignments, What am I missing?

    mattcom Level 1

      So I must be missing something basic here.

       

      This works and recognizes data changes:

      <mx:Label text="Search Title: [{this.appData.userPositionSearch.SearchFilterTitle}]"/>

      But if I do this it doesn't recognize changes:

      [Bindable]
      private var UserSearchData:Object;

       

       

      private function changeHandler():void

      {

           UserSearchData = this.appData.userPositionSearch;

      }

       

      <mx:Label text="Search Title: [{UserSearchData.SearchFilterTitle}]"/>

       

       

      The reason I'm interested in having a variable to the object assignment, is that I can use the same form for different types of searches (objects).

       

      Thanks in advance for the help.

        • 1. Re: Object assignments, What am I missing?
          Claudiu Ursica Level 4

          private var UserSearchData:Object; ->

           

          Object is not an IEventDispatcher you going to have to wrap it inside

          ObjectProxy or create your won custom Bindable class.

           

          C

          • 2. Re: Object assignments, What am I missing?
            mattcom Level 1

            .appData.userPositionSearch is a custom bindable class.  Does that count?

            • 3. Re: Object assignments, What am I missing?
              Claudiu Ursica Level 4

              I am assuming that when this line is happening you don't get the new changes:

               

              UserSearchData = this.appData.userPositionSearch;

               

              Right?

              C

              • 4. Re: Object assignments, What am I missing?
                mattcom Level 1

                Correct.  It only seems to stay at the default values of the VO.

                 

                Also (this may be a clue) if I try this:

                [Bindable]
                private var UserSearchData:UserPositionSearchVO;

                 

                UserSearchData.SearchFilterTitle = "blah";

                 

                I get this:

                 

                Error #1009: Cannot access a property or method of a null object reference

                • 5. Re: Object assignments, What am I missing?
                  Claudiu Ursica Level 4

                  Well the problem is that as I said Object cannot dispatch the "propertyChanged"

                  event since is not an IEventDispatcher. Your Object needs to be an

                  IEventDispathcer which if you use a custom Bindable class it will be since the

                  compiler will decorate/enhance it with the ability to dispatched events.

                   

                   

                  I am still not sure what you are trying to achieve so I am going to assume that

                  you want the generic Object so you can assign different object to it at runtime.

                  If that is the case you can have a bindable interface and drop in there the

                  properties that you want to observe changes on. So instead of

                  private var UserSearchData:Object;

                   

                  you will have:

                   

                  private var UserSearchData:IMyBindableInterface; implemented by a bindable class

                  which fill fire your changes. The part that I don't see is who trigger your

                  changeHandler() to execute.

                   

                  If you share more code details I will probably be able to understand better the

                  issue here. Right now I am just trying to make your Bindings execute.

                   

                  C

                  • 6. Re: Object assignments, What am I missing?
                    mattcom Level 1

                    Thanks for your conitinued effort Claudiu.

                     

                    I think something might be wrong with my SDK?  Following your suggestions I looked into ObjectProxy for a while and even the most basic examples are giving me errors.

                     

                    import mx.events.PropertyChangeEvent;
                    import mx.utils.ObjectUtil;
                    import mx.utils.ObjectProxy;
                    import mx.utils.StringUtil;
                    var a:Object = { name: "Tyler", age: 5, ssnum: "555-55-5555" };
                    var p:ObjectProxy = new ObjectProxy(a);
                    p.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, trace("changed"));
                    p.name = "Jacey";
                    p.age = 2;

                     

                     

                    I keep getting "1120: Access of undefined property p"

                     

                     

                    Back to the bindable class...

                     

                    I'm using Cairngorm and my VO is bound.

                    [Bindable]
                    public class UserPositionSearchVO

                     

                    using the Cairngorm architecture, it allows me to use what is working from my first post:

                    <mx:Label text="Search Title: [{this.appData.userPositionSearch.SearchFilterTitle}]"/>  where this.appData.userPositionSearch is a clone of UserPositionSearchVO.  Which is why I tried to do

                     

                    [Bindable]

                    UserSearchData:UserPositionSearchVO

                     

                    and then in the change handler

                     

                    UserSearchData = this.appData.userPositionSearch (which is updated every time the change handler is hit)

                     

                    however the data just stays the same in UserSearchData, just as it did if I assigned it to UserSearchData:Object.

                     

                     

                     

                    Perhaps I just can't explain it well.  After all, like I said in my first statement, this should work, and I must be missing something.

                    • 7. Re: Object assignments, What am I missing?
                      Claudiu Ursica Level 4

                      UserSearchData = this.appData.userPositionSearch (which is updated every time

                      the change handler is hit)

                       

                      Who is triggering the changeHandler? where are you calling it ? I am pretty sure

                      there is a simpler way but I don;t understand thy whole picture.

                       

                       

                      what is wrong with this.

                      Or why do you want to change it.

                       

                       

                      Sorry need to run now, I'll look into it in the evening.

                      C

                      • 8. Re: Object assignments, What am I missing?
                        mattcom Level 1

                        So the change handler is hit when an search filter is selected in a combobox.

                         

                        The reason I'm trying to handle it in a variable is the search box is a shared component that can search positions, alerts, and other things

                         

                        so {this.appData.userPositionSearch.SearchFilterTitle}  may need to be {VO2.SearchFilterTitle} in another part of the application and {VO3.SearchFilterTitle} in another.

                        • 9. Re: Object assignments, What am I missing?
                          Claudiu Ursica Level 4

                          Did you fixed this? I was off for a couple of days did not have time to look

                          into it?

                          C