Relative URL for HTTPService
forked from Passing String to the Constructor of Date Class (diff: 6)
I'm interested in relative url. If accessed by URLLoader or Loader, relative url is relative to that of html which embeds the swf. http://wonderfl.net/c/brRp On the other hand, when accessed by HTTPService, url is relative to that of the swf.
ActionScript3 source code
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ttIE
*/
<?xml version="1.0" encoding="utf-8"?>
<!-- forked from 9re's Passing String to the Constructor of Date Class -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="rssLoader.send()" paddingBottom="0" paddingLeft="0" paddingTop="0" paddingRight="0">
<mx:HTTPService id="rssLoader" result="onRSSLoaded(event)" url="/index.xml" resultFormat="text" showBusyCursor="true" fault="showError(event);" />
<mx:ArrayCollection id="feed" />
<mx:DataGrid id="reader" width="100%" height="100%" change='navigateToURL(new URLRequest(reader.selectedItem.link), "_blank")'>
<mx:columns>
<mx:DataGridColumn dataField="title"/>
<mx:DataGridColumn dataField="日付" width="150" />
</mx:columns>
</mx:DataGrid>
<mx:Script><![CDATA[
import flash.net.navigateToURL;
import flash.net.URLRequest;
import mx.controls.Alert;
import mx.rpc.events.*;
private function showError(e:FaultEvent):void {
Alert.show(e.fault.message, e.fault.faultString);
}
private function onRSSLoaded(e:ResultEvent):void {
var data:Array = [];
for each (var item:XML in XML(rssLoader.lastResult).channel.item) {
// pass string to Date constructor
var date:Date = new Date(item.pubDate.toString());
data.push( {
title : item.title,
link : item.link,
日付 : date.fullYear + '年' + (date.month + 1) + '月' + date.date + '日 ' + date.hours + '時'
});
}
feed.source = data;
reader.dataProvider = feed;
}
]]></mx:Script>
</mx:Application>