본문 바로가기

컴터/Flash & Flex

xml 읽어와 뿌리기 (creationComplete, result , fault)

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="feedRequest.send();">
 <mx:Script>
  <![CDATA[
   import mx.rpc.Fault;
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   
   private function resultHandler(event:ResultEvent):void{ //성공시
    dgPosts.dataProvider = event.result.rss.channel.item;
   }
   
   private function faultHandler(event:FaultEvent):void{ //실패시
    mx.controls.Alert.show(event.fault.message);
   }
  ]]>
 </mx:Script>
 <mx:HTTPService id="feedRequest" url="http://www.phpschool.com/gnuboard4/bbs/rss.php?bo_table=tipntech" useProxy="false"
 result="resultHandler(event)" fault="faultHandler(event)"
/>
 
 <mx:Panel title="HTTPService" height="100%" width="90%"
 paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" layout="vertical">
  <mx:DataGrid id="dgPosts" height="30%" width="100%" fontSize="12">
   <mx:columns>
    <mx:DataGridColumn headerText="Posts" dataField="title" />
    <mx:DataGridColumn headerText="Date" dataField="date" />
    <mx:DataGridColumn headerText="Link" dataField="link" />
    <mx:DataGridColumn headerText="category" dataField="creator" />
   </mx:columns>
  </mx:DataGrid>
 
  <mx:TextArea height="70%" htmlText="{dgPosts.selectedItem.description}" width="100%" editable="false" fontSize="12" />
 </mx:Panel>
</mx:Application>