After studying flex for a while, we found that actionscript3 is as dynamic as Ruby and can build very powerful clients. However, for some text-based systems, it is a bit cool-killing, however, in the future, the client is moving towards multi-media, because this will bring a higher user experience. I feel that flex has a good performance on the client, while Ruby is very clever in background business processing. As the two continue to mature and develop, there is reason to believe that the combination of the two will certainly open up a new world in enterprise-level air applications.
The following is an example of using Flex to subscribe to weather forecasts using Ruby on Rails.
Ruby:
Ruby code
- ClassWeatherscontroller <applicationcontroller
- Require 'rss/123'
- Require 'rss/123'
- Require 'open-Uri'
- DefShow
- Feed = "http://www.raychou.com/weather/rss.php? Id = # {Params [: Code]}"
- Content = ""
- Open (feed)Do| S |
- Content = S. Read
- End
- @ RSS= RSS: parser. parse (content,False)
- Render: xml =>@ RSS. Channel <span style = "color: # ff0000" ># directly send without parsing </span>
- End
- End
Class weatherscontroller <applicationcontroller require 'rss/100' require 'rss/100' require 'open-url' def show feed = "http://www.raychou.com/weather/rss.php? Id = # {Params [: Code]} "content =" "open (feed) Do | S | content = S. read end @ RSS = RSS: parser. parse (content, false) render: xml => @ RSS. channel # directly send endend without Parsing
Flex end:
Java code
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" width = "624" Height = "426">
- <Mx: SCRIPT>
- <! [CDATA [
- ImportMX. Events. closeevent;
- ImportMX. rpc. Events. resultevent;
- [Bindable]
- PrivateVaR cityname: array = [{label: "Beijing", data: "54511 "},
- {Label: "Nanjing", data: "58238 "},
- {Label: "Shanghai", data: "58367 "}
- ];
- [Bindable]
- PrivateVaR selecteditem: object;
- <Span style = "color: # ff0000"> // <span> process requests </span>. <span> no result data needs to be parsed, use it directly </span>
- PrivateFunction resultweather (Event: resultevent ):Void{
- Item1.text = event. Result. Channel. item [0]. Title. tostring ();
- Item2.text = event. Result. Channel. item [1]. Title. tostring ();
- Item3.text = event. Result. Channel. item [2]. Title. tostring ();
- }
- ]>
- </MX: SCRIPT>
- <! -- Send an HTTP request to the backend -->
- <Mx: httpservice result = "resultweather (event);" id = "getweather" url = "http: // localhost: 3000/weathers/Show" useproxy = "false">
- <Mx: Request>
- <Code >{ selecteditem. Data} </code>
- </MX: Request>
- </MX: httpservice>
- <Mx: panel x = "171" Y = "54" width = "418" Height = "333" layout = "absolute" Title = "Weather Forecast query" fontweight = "bold" fontsize =" 13 ">
- <Mx: ComboBox x = "120" Y = "28" id = "cmbcityname" dataprovider = "{cityname}" Close = "selecteditem#combobox(event.tar get). selecteditem;
- Getweather. Send (); "width =" 164 "fontsize =" 12 "/>
- <Mx: label x = "10" Y = "81" id = "Item1" text = "" width = "367" fontsize = "14" color = "#0a6464"/>
- <Mx: label x = "10" Y = "126" id = "item2" text = "" width = "367" fontsize = "14" color = "#0a6464"/>
- <Mx: Label x = "10" Y = "171" id = "item3" width = "367" fontsize = "14" color = "#0a6464"/>
- <Mx: Label x = "37" Y = "30" text = "select city"/>
- </MX: Panel>
- </MX: Application>
<? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" width = "624" Height = "426"> <mx: SCRIPT> <! [CDATA [import MX. events. closeevent; import MX. RPC. events. resultevent; [Bindable] private var cityname: array = [{label: "Beijing", data: "54511" },{ label: "Nanjing", data: "58238 "}, {label: "Shanghai", data: "58367"}]; [Bindable] private var selecteditem: object; // process the request without parsing the result data, you can directly use the private function resultweather (Event: resultevent): void {item1.text = event. result. channel. item [0]. title. tostring (); item2.text = even T. result. channel. item [1]. title. tostring (); item3.text = event. result. channel. item [2]. title. tostring () ;}]]> </MX: SCRIPT> <! -- Send an HTTP request to the backend --> <mx: httpservice result = "resultweather (event);" id = "getweather" url = "http: // localhost: 3000/weathers/Show "useproxy =" false "> <mx: Request> <code> {selecteditem. data} </code> </MX: Request> </MX: httpservice> <mx: panel x = "171" Y = "54" width = "418" Height = "333" layout = "absolute" Title = "Weather Forecast query" fontweight = "bold" fontsize =" 13 "> <mx: comboBox x = "120" Y = "28" id = "cmbcityname" dataprovider = "{cityname}" Close = "selecteditem#combobox(event.tar get ). selecteditem; getweather. send (); "width =" 164 "fontsize =" 12 "/> <mx: label x = "10" Y = "81" id = "Item1" text = "" width = "367" fontsize = "14" color = "#0a6464"/> <MX: label x = "10" Y = "126" id = "item2" text = "" width = "367" fontsize = "14" color = "#0a6464"/> <MX: label x = "10" Y = "171" id = "item3" width = "367" fontsize = "14" color = "#0a6464"/> <mx: label x = "37" Y = "30" text = "select city"/> </MX: Panel> </MX: Application>