Hi flexcoders,

Although I've had good luck with data binding in Flex in general, I'm stuck on one problem.

The setup is kind of complicated, but basically, I've got a QuotesModel object that talks to a server and provides StockQuote value objects. The QuotesModel class has a getQuote method defined like this:

[ChangeEvent("getQuoteUpdated")]
public function getQuote(ticker:String):StockQuote {
return __allQuotes[ticker];
}

The class also contains code that does a dispatchEvent({type:"getQuoteUpdated"}); whenever __allQuotes is updated with new data. The idea is that I want things that are bound to getQuote([some ticker]) to pull the new data when the getQuoteUpdated event is dispatched.

This appears to work for simple cases, i.e. if I have a label that's defined like this

<fcon:QuotesModel id="quotes"/>
<!-- PortfolioEntryModel is a value object that is bound elsewhere to the currently selected row of a DataGrid -->
<fcon:PortfolioEntryModel id="currentEntry"/>
<mx:Label id="lastPrice" text="{quotes.getQuote(currentEntry.ticker).lastPrice}"/>


In the above case, the lastPrice label gets updated correctly when the QuotesModel receives new data periodically from the server. However, when I do this:

<fcon:QuotesModel id="quotes"/>
<!-- PortfolioEntryModel is a value object that is bound elsewhere to the currently selected row of a DataGrid -->
<fcon:PortfolioEntryModel id="currentEntry"/> <!-- create a holder for the StockQuote associated with the ticker property of the currently selected row (PortfolioEntryModel) -->
<fcon:StockQuote id="currentQuote"/>
<mx:Binding source="{quotes.getQuote(currentEntry.ticker)}" destination="currentQuote"/>
<!-- now bind the label to the holder object, not the getQuote function result itself -->
<mx:Label id="lastPrice" text="{currentQuote.lastPrice}"/>


the lastPrice label text does _not_ get updated when QuotesModel dispatches its getQuoteUpdated event. For lastPrice to see the changes, I have to re-click on the DataGrid, which causes currentEntry to get re-updated, after which the bindings appear to do the rest of the work correctly.

Is there something wrong with the approach I'm taking in which currentQuote serves as an intermediate holding object? I need to do it this way because currentQuote is actually going to be passed as a property of another mxml component that will encapsulate the display of details associated with the current entry's stock quote.

I realize this is a complicated question but I need to determine whether my approach is wrong or there's a bug in the system somewhere. Thanks

- rdo
FinancialContent, Inc.





Reply via email to