tags:

views:

44

answers:

3

I have a main parent application with 2 children (the children are siblings). I am trying to pass data from sibling1 to parent and then to sibling2 but can't quite figure out how to do it. Here's code from the parent:

<fx:Script>
<![CDATA[

[Bindable] private var _myData;

public function set myData(value:Object):void{
    _myData=sibling1.autoComplete.selectedItem;
}

]]>
</fx:Script>

<local:sibling1 myData="{myData}"/>
<local:sibling2 />

In sibling1 I have a search box named autoComplete. In sibling2 I need to echo the item I selected from sibling1.

I'm trying to pass the data from sibling1 to the parent and then to sibling2 (and then to siblings 4,5,6,etc., so I imagine this makes the most sense?)

+1  A: 

For echoing the selected value in another component (I'm assuming your data providers contain simple strings here), you can just bind to the selected item like so:

<s:Label text="{sibling1.autoComplete.selectedItem}"/>
Wade Mueller
that didn't work. The data I want to pass is pulled from a database and is an object
ginius
How about trying to bind to sibling1.autoComplete.selectedItem.someProperty?
Wade Mueller
that didn't work either
ginius
A: 

I think making your application event driven will make the most sense.

What you should do (IMHO) is dispatch the event from the component to the parent component and then do whatever you want from the parent to the children (siblings of the dispatching component).

This will also decouple your code and will make your components reusable.

Good luck

Avi Tzurel
I'm still kind of new to flex. Can you point me to a tutorial as I'm not really sure what you just said.
ginius
sure, let's talk about it like simple language.event is something that happens in the applciation, it can be anything from Click to timer.Mate uses a map that will say....When X happens do thiswhen Y happens do thisWhen Z happens do this, this, and this, by using data from this.it's a very powerful feature once you grasp how to use it's power.The best example to this, without complicating you with other things is this:http://mate.asfusion.com/assets/content/examples/helloworld/srcview/Good luck
Avi Tzurel
A: 
ginius