Stock Quotes

The example for the Getting Started guide. It shows:

  1. How to handle a custom event in the Event Map
  2. How to use the view Injectors to get the data from the Model Manager

 

RemoteObject version

This is the version described in the Getting Started guide. It uses RemoteObject to call a ColdFusion service. The backend could be changed to other AMF implementation such as Java as long as the service returns a numeric value.

View Source

Download Source

 

WebService version

We have also created a version of this example that does not require ColdFusion. It calls the Stock Quotes web service directly. Because of that, it also has an additional class that parses the data before passing it to the QuoteManager class that stores it. In order to that, we added a MethodInvoker tag between the <resultHandlers> tag and the MethodInvoker tag that called the QuoteManager.

View Source

Download Source

<br /><div id="inlineExample"> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject('/assets/content/examples/stockQuoteExample/StockQuoteExample.swf', 'website', '400', '200', '9', '#FFFFFF'); so.useExpressInstall('/assets/scripts/swfobject/expressinstall.swf'); so.addParam('menu', 'false'); so.write('inlineExample'); // ]]> </script> </div>

16 responses

  1. This example needs libs/Mate_06_2.swc not the Mate_06_1.swc bundled here.
  2. Hi Matt,
    Sorry about that. I've updated the zip, I hope it works now.
    By the way, were you the person that came to me before the session?
  3. No problem at all. Yes I was one of the guys that brought this up before the presentation. You were right that this was the problem for getting it to compile. This is a nice, clean example. Thanks!
  4. Hi,

    This is very interesting stuff, much easier to follow than cairngorm so far... But I do have one simple question?

    I'm unsure of how the program flow works withinthe result handlers.

    Does each MethodInvoker get called in sequence? And how the result of QuoteSericeParser is passed along to QuoteManager. I can see hints in the code such as lastReturn.lastPrice, but I'd just like a bit of clarification on this point if possible?

    Many thanks,

    Matt Law

             <resultHandlers>
                <!-- parse the results -->
                <MethodInvoker generator="{QuoteServiceParser}" method="parseQuoteResults"
                   arguments="{resultObject}" cache="false" />
                   
                <!-- store the last price from the parsed results -->
                <MethodInvoker generator="{QuoteManager}"
                   method="storeQuote" arguments="{lastReturn.lastPrice}"/>
             </resultHandlers>
  5. Hi Matt,<br />That's right, all tags inside the handlers are executed in order unless they are nested inside the result of an asynchronous call (resultHandlers or faultHandlers for example). And yes, the result is sent to the storeQuote function by using lastReturn.<br /><br />See Using lastReturn for more information. Also see EventHandlers, the last section called &quot;Order of the inner tags is important&quot;.
  6. Should it be possible to change the quoteManager.as class to use getter and setter rather than the public property? <br /><br /> private var _price:Number = 0;<br /><br /> public function set price(value:Number):void {<br /> &nbsp;&nbsp;&nbsp;_price = value;<br /> }<br /><br /> public function get price():Number {<br /> &nbsp;&nbsp;&nbsp;return _price;<br /> }<br /><br />So this requires no change in the MainEventMap<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;PropertyInjector targetKey=&quot;price&quot; source=&quot;{QuoteManager}&quot; sourceKey=&quot;price&quot; /&gt;<br /><br /> remains as is but should not access the getter, right?
  7. Dirk,<br />Public properties and public getter/setter are basically interchangeable, so yes, the <a href="PropertyInjector</a>">http://mate.asfusion.com/page/documentation/tags/propertyinjector">PropertyInjector</a>; can stay the same and the setter will be called instead.
  8. I try to inject the resultObject directly in the current view (that is the view which reference in the EventMap) without the QuoteManager and Injectors.<br />Just like:<br />&lt;EventMap&gt;<br /> &lt;EventHandlers type=&quot;&quot;&gt;<br /> &lt;RemoteObjectInvoker method=&quot;loadUsers&quot;&gt;<br /> &lt;resultHandlers&gt;<br /> &lt;XXXTag target=&quot;currentView&quot; targetKey=&quot;users&quot; source=&quot;{resultObject}&quot; /&gt;<br /> &lt;/resultHandlers&gt;<br /> &lt;/RemoteObjectInvoker&gt;<br />&lt;/EventMap&gt;<br /><br />Which tag can do this in this case?
  9. At last, I used the DataCopier Tag implement the case.<br />Like this:<br />&lt;EventMap&gt;<br />&lt;EventHandlers type=&quot;&quot;&gt;<br />&lt;RemoteObjectInvoker method=&quot;loadUsers&quot;&gt;<br />&lt;resultHandlers&gt;<br />&lt;DataCopier destination=&quot;{event.target}&quot; destinationKey=&quot;varInView&quot; source=&quot;result&quot; /&gt;<br />&lt;/resultHandlers&gt;<br />&lt;/RemoteObjectInvoker&gt;<br />&lt;/EventMap&gt;
  10. The index.html for Source View is missing :(<br /><br />Apart from that mate seems to be a nice lightweight framework to me :) Go on...
  11. Heringsfilet,<br />index.html is just the Flex Builder generated wrapper, nothing special there, and not really part of the source.
  12. Suppose I have two QuotePanel instances (same QuotePanel class) to support my use cases. The return of the price should be sent to the panel that dispatched the QuoteEvent not the other. How do I achieve that?<br /><br />For example if I have the following in the main application<br /><br /> &lt;maps:MainEventMap /&gt;<br /><br />&nbsp;&nbsp;&nbsp;&lt;views:QuotePanel /&gt;<br />&nbsp;&nbsp;&nbsp;&lt;views:QuotePanel /&gt;<br /><br />The quote will be sent to both panels.<br /><br />Thanks.
  13. Ok, I found the targetId attribute mentioned in the doc. That will work for the example I use in my last post, if I define the ids with the QuotePanel.

    In situations that instances of QuotePanel are created in runtime, targetId won't work, since the ids would be dynamic.
  14. Colin,
    See the Hello World example to do what you need (using the CallBack tag and without using targetId).
  15. Could you provide an HTTPService example? Or could you provide/point me to an example other than Stock Quotes that uses HTTPServices? I really am just getting started and trying to learn Mate... I'm on a project that is using HTTPServices.
  16. Thanks you for your description.

Comments now closed