<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" viewSourceURL="srcview/index.html">
<mx:HTTPService id="itemSearchSrv" url="http://webservices.amazon.co.jp/onca/xml" useProxy="false"
result="itemSearchResultHandler(event)"
fault="requestFaultHandler(event)"
showBusyCursor="true" resultFormat = "e4x"/>
<mx:states>
<mx:State name="searchResultState">
<mx:SetProperty target="{resultPanel}" name="visible" value="true"/>
</mx:State>
</mx:states>
<mx:Style>
ToolTip {
fontFamily: ;
fontSize: 12;
backgroundColor: #FFCCCC;
}
</mx:Style>
<mx:HBox x="10" y="10">
<mx:Panel width="220" height="120" layout="absolute" id="searchPanel" title="商品検索" fontFamily="_ゴシック" fontSize="12">
<mx:Label x="10" y="10" text="サーチ:" id="keywordLabel" fontFamily="_ゴシック" fontSize="10"/>
<mx:TextInput x="45" y="10" width="145" id="searchText" text="WEB+DB Press" fontFamily="_ゴシック" fontSize="10"/>
<mx:ComboBox x="10" y="50" id="categoryCombobox" width="120" fontFamily="_ゴシック">
<mx:dataProvider>
<mx:ArrayCollection>
<mx:source>
<mx:Object label="本" data="Books"/>
<mx:Object label="ミュージック" data="Music"/>
<mx:Object label="ソフトウェア" data="Software"/>
<mx:Object label="DVD" data="DVD"/>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button x="140" y="50" label="検索" id="searchButton" fontFamily="_ゴシック" click="itemSearch(),currentState='searchResultState'"/>
</mx:Panel>
<mx:Spacer/>
<mx:Panel width="600" height="330" id="resultPanel" title="検索結果" fontFamily="_ゴシック" fontSize="12" visible="false" showEffect="Fade" verticalScrollPolicy="off">
<mx:TileList x="0" y="0" id="itemThumbnailList" dataProvider="{thumbnailCollection}"
width="100%" height="290" columnCount="5"
backgroundColor="#ffffff" selectionColor="0xFFCC66" rollOverColor="0xFFFF99">
<mx:itemRenderer>
<mx:Component>
<mx:VBox height="140" horizontalAlign="center" toolTip="{data.TitleName}"
borderColor="0xCCCCCC" borderStyle="inset">
<mx:Image id="itemImage" source="{data.imageURL}" height="70"
horizontalAlign="center" verticalAlign="middle"/>
<mx:Text id="itemTitle" height="30" width="100" text="{data.TitleName}"
fontFamily="_ゴシック" fontSize="12" textAlign="left" selectable="false"/>
<mx:Label id="itemPrice" width="100" text="{data.PriceAmount}"
fontFamily="_ゴシック" fontSize="12"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:TileList>
</mx:Panel>
</mx:HBox>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
private var _ECS_SERVICE:String="AWSECommerceService";
private var _AWS_ACCESS_KEY_ID:String="[取得した登録ID(例:0123456789ABCDEFGHI)]";
default xml namespace = "http://webservices.amazon.com/AWSECommerceService/2005-10-05";
Security.loadPolicyFile("http://xml.amazon.com/crossdomain.xml");
[Bindable]
private var thumbnailCollection:ArrayCollection = new ArrayCollection();
private function itemSearch():void{
var operation_str:String="ItemSearch";
var index_str:String=categoryCombobox.selectedItem.data;
var keyword_str:String=searchText.text;
var responseGroup_str:String="Medium";
var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str ,
SearchIndex:index_str , Keywords:keyword_str,ResponseGroup:responseGroup_str};
itemSearchSrv.send(sendObject);
}
private function itemSearchResultHandler(event:ResultEvent):void{
trace("◆◆◆◆◆◆◆◆検索結果表示◆◆◆◆◆◆◆◆");
trace(itemSearchSrv.result);
trace("◆◆◆◆◆◆◆◆検索結果表示◆◆◆◆◆◆◆◆");
thumbnailCollection.removeAll();
var _itemObj:Object=event.result;
var itemXmlList:XMLList = _itemObj.Items.Item;
for(var i:Number=0;i<itemXmlList.length();i++){
var currentItemsObj:Object=itemSearchSrv.result.Items.Item[i];
var itemTitle:String=currentItemsObj.ItemAttributes.Title;
var itemSmallImageURL:String=currentItemsObj.SmallImage.URL;
var itemPrice:String=currentItemsObj.OfferSummary.LowestNewPrice.FormattedPrice;
var itemListPrice:String=currentItemsObj.ItemAttributes.ListPrice.FormattedPrice;
if(itemPrice==""){
itemPrice=itemListPrice;
}
trace("");
trace(itemTitle);
trace(itemSmallImageURL);
trace(itemPrice);
trace("");
if(itemSmallImageURL==""){
itemSmallImageURL="images/no_image_ss.gif";
}
var itemViewObj:Object={TitleName:itemTitle , imageURL:itemSmallImageURL , PriceAmount:itemPrice};
thumbnailCollection.addItem(itemViewObj);
}
}
private function requestFaultHandler(event:FaultEvent):void{
Alert.show(event.fault.faultstring, "Error requesting data");
}
]]>
</mx:Script>
</mx:Application>