Question: I have a simple app that consists of:

**Model**

* Items
* Filter criteria applied to that list of items

**Views**

* WelcomePage
* MainItemsPage
* FilterEditPage

I am using MVVM Light and Windows Phone 7

I currently have 3 ViewModels, one for each View. In the past I have had a single ViewModel which made the comunication which I am about to ask about very easy. However I wanted to go with the 3 seperate VMs as that seems to be the correct way.

The WelcomePage is able to set one of the Filter criteria before navigating to the MainItemsPage. The MainItemsPage is bound to an Items property that is exposed by its ViewModel. That ViewModel needs to have filtered that list depending on the current filter criteria. The FilterEditPage allows the user to edit the full criteria set of 4 variables. When the criteria is changed the Items collection used in the ViewModel for MainItemsPage needs to be refiltered.

The question is how I flow the Filter changes through the app. I know that MVVM has the concept of Messaging and the MVVM Light toolkit provides the Messenger class. However what I am struggling with is where does the responsibility lie for sending those messages?

1. Do the 3 VMs go to the Model whenever they need to work with the current Filter set?
2. Do all Filter updates go through the FilterEditViewModel and that in turn broadcasts a filter change message?
3. Do I go back to a single VM for all the Views?

I cannot see 1. working because something will need to trigger the VMs to go back to the Model
I know I can get 3. working right now with no problem. Is it that wrong?

TIA

Pat Long

Answer: 
You can use [contains](http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#contains%28%29) method

> 
> `public function contains(child:DisplayObject):Boolean`  
> 
>  Determines whether the specified display object is a child of the `DisplayObjectContainer` instance or the instance itself. The search includes the entire display list including this `DisplayObjectContainer` instance, grandchildren, great-grandchildren, and so on.
> 
> 
> 

```
function haveCommonParent(a:DisplayObject, b:DisplayObject):Boolean
{
  for(var p:DisplayObjectContainer = a.parent; p != null; p = p.parent)
  {
      if(p.contains(b))
          return true;
  }
  return false;
}

```

Might be slow for huge display lists.

Update: get the common parent, if any. This will return a `Stage` object if both are on stage.

```
function getCommonParent(a:DisplayObject, b:DisplayObject):DisplayObjectContainer
{
  for(var p:DisplayObjectContainer = a.parent; p != null; p = p.parent)
  {
      if(p.contains(b))
          return p;
  }
  return null;
}

```
```
var mc:MovieClip;
while (mc.parent != null && mc.parent != targetParent)
{
    mc = mc.parent;
}

```