1 Reply Latest reply on May 10, 2011 6:07 AM by UbuntuPenguin

    Binding To a Propery - Inside an ArrayCollection Problem

    dataDash

      I'm trying to make an editor where users can select an editable item from a list (each item in the list might be a different type of editable object). When the user selects an item from the list its editable properties show up in a panel with a suitable item editor.

      example.jpg

       

      The problem I'm having is I don't want all item properties to be editable and I need to be able to specify what type of editor should be used e.g. TextInput, ColorPicker or custom editor.

       

       

      I thought about creating an EditableItem objects which could have an ArrayCollection called editableItems which holds what can be edited and what type of editor to use in a EditConf object:

       

       

      package

       

      {

       

          [Bindable]

       

          public class EditConf

       

          {

       

            

       

              public var value:*;

       

              public var editor:String = "DefaultEditor";

       

            

       

              public function EditConf(value:*, editor:String)

       

              {

       

                  this.value = value;

       

                  this.editor = editor;

       

              }

       

          }

       

      }

       

       

      Inside the EditableItem would look something like this with an ArrayCollection holding the EditConf objects.

       

       

      package

       

      {

       

          import mx.collections.ArrayCollection;

       

       

          [Bindable]

       

          public class EditableItem

       

          {

       

              public var label:String;

       

              public var colour:uint;

       

            

       

              public var nonEditableVar:String;

       

              public var nonEditableVar2:Boolean;

       

            

       

              public var editableItems:ArrayCollection;

       

            

       

              public function EditableItem()

       

              {

       

                  editableItems.addItem(EditConf(label, "TextInput"));

       

                  editableItems.addItem(EditConf(colour, "ColorPicker"));

       

              }

       

          }

       

      }

       

       

      The problem with this is when you assign the editor - say a TextInput to edit the value "label" from the editableItems ArrayCollection it updates the editableItem ArrayCollection but not the variable "label". I thought the ArrayCollection would just hold a pointer to "label" so it would update the variable but no such luck.

       

       

      Does anyone know of a better way to create the application above or why the binding does function as I expected?

       

       

      Many Thanks
        • 1. Re: Binding To a Propery - Inside an ArrayCollection Problem
          UbuntuPenguin Level 4

          It sounds more like an architecture problem.  If I had a problem like this, I would have a model class hold my selectedItem.  This "selectedItem" property would be injected into a presenter model through a setter function.  In the setter function, the presenter would look at the selectedItem and decide which properties on the view class ( viewstack or states ) should be editable.

           

          I have some misgivings about the value objects holding the type of editor they should use, that sounds like something that should be delegated to a UI/Presenter class.

          1 person found this helpful