Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
27
examples/StockQuote/src/stocks/service/QuoteServiceParser.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |