Skip navigation
Currently Being Moderated

Data binding a library component to the application main page data

Jun 14, 2013 1:04 PM

In my main application template I create several data models that I want to use throughout my application.  To do this I have created datamodels (ArrayCollections really) and bind them in the main page like this:



public var AppModel:AppDataModel = AppDataModel.getInstance();


Inside the AppModel I have several different collections of data that I want to use to populate things like datagrids or ComboBoxes elsewhere in the application.  My question is how do I pass the AppModel to my other components???


I've tried things like the following without success.





I would like to just import the AppModel into my component and do that reguarly when the component is part of the main application.  Problem is this is a library component so I need a different method of passing my main data sets into it.


Any thoughts???

  • Currently Being Moderated
    Jun 17, 2013 7:38 AM   in reply to

    Did you try having everyone just access AppDataModel.getInstance()?

    Mark as:
  • Currently Being Moderated
    Jun 18, 2013 12:23 PM   in reply to

    Have you tried using an Interface?

    Mark as:
  • Currently Being Moderated
    Jun 18, 2013 12:47 PM   in reply to

    I'm not quite sure what you mean by library component.  I think of library components as UI widgets which are then combined into a view.  That view binds data from a model to various properties in the UI widgets.


    If you are trying to re-use a view, then it has to make assumptions about the model.  Otherwise, the view code contains the bindings from the model to the widget properties.

    Mark as:
  • Currently Being Moderated
    Jun 18, 2013 2:01 PM   in reply to

    Well, a Flex Library Project can be used to hold a bunch of slightly customized controls which more or less have the same API surface as the original, or it can hold complex views, which is my understanding of what you are trying to do.


    Whenever you want reusability, you usually need some form of abstraction.  There are simple abstractions like "pass in the model" or "pass in the class name of the model that implements this interface", or really complex ones like "pass in the name of a model I will find via a ModelLocator" or "I'm always going to look for a model named 'foo' in a ModelLocator".


    There are various application-level frameworks like Swiz, Parsley and Cairngorm that implement ways of hooking all of this stuff up in a reusable fashion.  Frameworks typically have size and performance overhead because it simply takes code to create abstractions, but it is worth it to many folks.


    You also seem to be describing what I call "second-level abstractions" or "schema mapping" where the view's widgets are not tied to various properties described in an interface, but rather, you want the widgets to be flexible about which property in the data object to use.  That requires some sort of mapping.  Some folks pass in an XML file describing that mapping.  Others use metadata.  There are other ways as well.  It all depends on how much flexibility you need, but that flexibility can cost you in performance and size.




    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points