Your approach seems right on.  This shouldn't make a difference, but try removing the

<fcon:StockQuote id="currentQuote"/>

 

and replacing it with

<mx:Script>

  var currentQuote : mypackage.StockQuote;

</mx:Script>

 

The fact that the update works when currentEntry changes but not the getQuotesUpdated event is strange.  You might also try changing currentQuote to setter/getter and putting in a trace to see if it's getting called when just getQuotesUpdated is firing.  And then finally maybe put an event handler on your quotes object for getQuotesUpdated (you'll need to add [Event("getQuotesUpdated")] to the top of your quotes class) to see if it is firing when you expect.

 

So what you're doing appears right, just need to do some more debugging to figure out where things are going wrong and if it starts to look like Flex is doing the wrong thing we can try to get more info.

 

Matt

 

 

-----Original Message-----
From: Ryan Olson [mailto:[EMAIL PROTECTED]
Sent:
Wednesday, May 26, 2004 10:47 AM
To: [email protected]
Subject: [flexcoders] Data binding chain problem

 

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