Skip to content

Commit

Permalink
added stock quote example (flex 4)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhess committed Apr 28, 2009
1 parent a35e1ef commit f31babf
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 0 deletions.
Binary file added examples/StockQuote/libs/Glue0.2.a.swc
Binary file not shown.
Binary file added examples/StockQuote/libs/Mate_8.6b.swc
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/StockQuote/src/StockQuote.mxml
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:glue="stocks.glue.*" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" xmlns:view="stocks.view.*" xmlns:control="stocks.control.*">

<fx:Declarations>
<control:MainGlue/>
</fx:Declarations>

<s:layout>
<s:VerticalLayout horizontalAlign="center"/>
</s:layout>

<view:QuotePanel/>

</s:Application>
16 changes: 16 additions & 0 deletions examples/StockQuote/src/stocks/control/MainGlue.mxml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<GlueMap xmlns="http://glue.seanhess.net/2009" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:view="stocks.view.*" xmlns:control="stocks.control.*" xmlns:mate="http://mate.asfusion.com/" xmlns:service="stocks.service.*">
<fx:Declarations>

<!-- SERVICES -->

<service:QuoteService id="quoteService"/>

<Glue>
<view:QuotePanel id="quotePanel"/>
<Route event="{QuotePanel.GET_QUOTE}" call="quoteService.getQuote(quotePanel.quote)"/>
</Glue>

</fx:Declarations>
</GlueMap>

13 changes: 13 additions & 0 deletions examples/StockQuote/src/stocks/model/Quote.as
@@ -0,0 +1,13 @@
package stocks.model
{
/**
* The model object gets passed around to everybody. These should be global
* models? Or at least pass
*/
[Bindable]
public class Quote
{
public var symbol:String;
public var price:Number;
}
}
46 changes: 46 additions & 0 deletions examples/StockQuote/src/stocks/service/QuoteService.mxml
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<fx:Object xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:business="com.asfusion.mate.stockQuoteExample.business.*" xmlns:service="stocks.service.*">

<fx:Declarations>
<mx:HTTPService id="quoteService"
url="http://judstephenson.com/api/Quotes/Realtime/{quote.symbol}"
resultFormat="object"
result="onResult(event)"
fault="onFault(event)"
/>

<service:QuoteServiceParser id="parser"/>
</fx:Declarations>

<fx:Script>
<![CDATA[
import mx.rpc.AbstractOperation;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import stocks.model.Quote;
[Bindable]
private var quote:Quote;
public function getQuote(quote:Quote):void
{
this.quote = quote;
quoteService.send();
}
private function onResult(event:ResultEvent):void
{
quote.price = parser.getPrice(event.result);
}
private function onFault(event:Event):void
{
Alert.show("There was an error");
}
private function onLoad(event:Event):void{
trace("WOOT");
}
]]>
</fx:Script>
</fx:Object>
27 changes: 27 additions & 0 deletions examples/StockQuote/src/stocks/service/QuoteServiceParser.as
@@ -0,0 +1,27 @@
package stocks.service
{

// --------------------------------------------
// This helper class parses data coming from the
// stock quotes web service and converts it into
// an object

public class QuoteServiceParser
{
// --------------------------------------------
// The webservice returns a string representation
// of an xml object. We first convert to xml
// and then get the properties from it
public function getPrice(info:Object):Number {
try {
var price:Number = info.quote.stock.price.current;
return price;
}
catch (e:Error)
{
}
return 0;
}

}
}
31 changes: 31 additions & 0 deletions examples/StockQuote/src/stocks/view/QuotePanel.mxml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<s:Panel title="Stock Quotes" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" width="400" height="300">

<fx:Script>
<![CDATA[
import stocks.model.Quote;
public static const GET_QUOTE:String = "getQuote";
[Bindable] public var quote:Quote = new Quote();
public function getQuote():void
{
quote.symbol = input.text;
dispatchEvent(new Event(GET_QUOTE));
}
]]>
</fx:Script>

<s:layout>
<s:VerticalLayout/>
</s:layout>

<s:Group>
<s:layout><s:VerticalLayout/></s:layout>
<mx:Label text="Symbol:"/>
<s:TextInput id="input" enter="getQuote()"/>
<s:Button label="Get Quote" click="getQuote()"/>
</s:Group>

<mx:Label text="Price: {quote.price}" />
</s:Panel>

0 comments on commit f31babf

Please sign in to comment.