I can't believe this is so difficult. All I want to do is be able to access my main application data from a library component. Isn't that the point of having library components anyway??? I've been fighting with this for the better part of two hours now... grrrr >:(
Did you try having everyone just access AppDataModel.getInstance()?
Flex harUI, That works fine in the main application. The problem is in a library component that is associated to the main application. What I need to know is how can I get a library component to access the global data models defined ion the main application and then be able to bind them. I really don't want to push out a data model to every library component I use every time a change is made to the data. That is why binding is so cool, so I can change the data in one place and every thing that needs it see the change.
Have you tried using an Interface?
The library component is an interface. What I want to do is use my main application to provide data that will be used in datagrids and comboboxes within the library components. But because it is a library component I want to be able to use it in multiple applications. For instance one of the dropdown lists is called Status.
In one application Status refers to license status, in another Status refers to a customer, and in a third Status refers to an internal user. The main application supplies the data to the library component and it displays the data.
Does this even make sense or do I need to rewrite what it is I am trying to do??? I know it can create a global data set and then have included library components reference it somehow. I am able to push the data to the library component when I run an initialization section of code but I want to be able to bind the variouls controls in my library components to the global data sets so I don't have to push the data out every time it gets updated. Or don't I have a choice???
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.
By library component I am talking about what is created in Flash Builder when you click File -> New ->Flex Library Project. In my various libraries I have things like interfaces to manage people type of information (first name, last name, middle name, ssn, DOB, etc...). In these interfaces I have drop down controls like Status so I can change the status of a customer or employee. .
To include these library components into my main application I go into the preferences and link the library to the application in the build path.
Currently, when I first launch the application I have initialization routines that push data out to these library components. Problem is I just came across an instance where two library components are using the same data set. If one of them changes the data then I have to push the data to the other.
When I build these types of controls in the main application I import the main application data model and bind the UI controls to that data model.
What I want to do is to be able to treat a library component (maybe module is a better word here) like a component that was built in the main application. That way if the data changes it is reflected everywhere and a data push to the various components is not needed. Just update the main data model and I'm done.
Problem is how do I tell the library component the name of the main application global data model and import it. THe code has to be flexible enough so I can pass in the name of the datamodel and not hard code it. After all I am trying to make the library component universal for multiple applications.
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.