<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" backgroundColor="0xCCCCCC" 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:HTTPService id="itemDetailsSrv" url="http://webservices.amazon.co.jp/onca/xml" useProxy="false"
result="showItemDetailsResultHandler(event)"
fault="requestFaultHandler(event)"
showBusyCursor="true" resultFormat = "e4x"/>
<mx:Style>
ToolTip {
fontFamily: ;
fontSize: 12;
backgroundColor: #FFCCCC;
}
</mx:Style>
<mx:HBox x="10" y="10">
<mx:VBox id="vboxLeft">
<mx:Panel width="220" height="120" layout="absolute" title="商品検索" id="searchPanel" cornerRadius="8" fontSize="12" fontFamily="_ゴシック">
<mx:Label x="10" y="10" text="サーチ:" id="keywordLabel" fontFamily="_ゴシック" fontSize="10"/>
<mx:TextInput x="45" y="10" width="145" id="searchText" text="Amazon" fontSize="10" fontFamily="_ゴシック"></mx:TextInput>
<mx:ComboBox x="10" y="50" width="120" id="categoryCombobox" 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" id="searchButton" label="検索" fontFamily="_ゴシック" click="itemSearch(),currentState='searchResultState'"></mx:Button>
<mx:ControlBar height="10" id="searchPanelControlBar"></mx:ControlBar>
</mx:Panel>
</mx:VBox>
<mx:Spacer/>
<mx:Panel id="resultPanel" width="600" height="370" cornerRadius="8" backgroundColor="#FFFFFF" fontFamily="_ゴシック" fontSize="12" visible="false" showEffect="Fade" title="検索結果" verticalScrollPolicy="off">
<mx:VBox width="100%" id="vboxRight">
<mx:TileList id="itemThumbnailList" dataProvider="{thumbnailCollection}"
x="0" y="0" width="100%" height="290" columnCount="5"
itemClick="getItemDetails(),setHistoryFromThumbnail(),currentState='moveItemListState'"
dragEnabled="true"
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:VBox>
<mx:ControlBar id="resultPanelControlBar" height="50"></mx:ControlBar>
</mx:Panel>
</mx:HBox>
<mx:states>
<mx:State name="searchResultState">
<mx:SetProperty target="{searchPanel}" name="height" value="180"/>
<mx:AddChild target="{searchPanelControlBar}" position="before">
<mx:Label x="19" y="86" text="検索結果:" id="totalResultLabel" fontSize="12" fontFamily="_ゴシック"/>
</mx:AddChild>
<mx:AddChild target="{searchPanelControlBar}" position="before">
<mx:Label x="14" y="112" text="総ページ数:" id="totalPageLabel" fontSize="12" fontFamily="_ゴシック"/>
</mx:AddChild>
<mx:AddChild target="{searchPanelControlBar}" position="before">
<mx:TextArea id="searchTotal" text="{itemSearchSrv.result.Items.TotalResults}" x="86" y="85" height="20"
fontFamily="_ゴシック" fontSize="12" width="60" textAlign="right" editable="false"/>
</mx:AddChild>
<mx:AddChild target="{searchPanelControlBar}" position="before">
<mx:TextArea id="pageTotal" text="{itemSearchSrv.result.Items.TotalPages}" x="86" y="111"
fontFamily="_ゴシック" fontSize="12" height="20" width="60" textAlign="right" editable="false"/>
</mx:AddChild>
<mx:AddChild target="{searchPanelControlBar}" position="before">
<mx:Label x="148" y="88" text="件" fontFamily="_ゴシック" fontSize="12"/>
</mx:AddChild>
<mx:AddChild target="{searchPanelControlBar}" position="before">
<mx:Label x="148" y="113" text="ページ" fontFamily="_ゴシック" fontSize="12"/>
</mx:AddChild>
<mx:SetProperty target="{resultPanel}" name="visible" value="true"/>
<mx:AddChild target="{resultPanelControlBar}" position="lastChild">
<mx:Button label="次へ>>" id="nextPageButton" click="pageSearch(1)" fontFamily="_ゴシック" fontSize="12"/>
</mx:AddChild>
<mx:AddChild target="{nextPageButton}" position="before">
<mx:Button label="<<前へ" fontFamily="_ゴシック" fontSize="12" click="pageSearch(-1)" id="backButton"/>
</mx:AddChild>
</mx:State>
<mx:State name="showItemDetailsState" basedOn="searchResultState">
<mx:AddChild target="{vboxLeft}" position="lastChild">
<mx:Panel id="favoriteAndHistoryPanel" width="220" height="485" cornerRadius="8" title="お気に入り・表示履歴" fontFamily="_ゴシック" fontSize="12" >
<mx:Accordion id="accordionSet" height="100%" openDuration="800">
<mx:Canvas label="お気に入り" width="100%" height="100%">
<mx:List id="favoriteList" dataProvider="{favoriteCollection}" labelField="TitleName" width="198" height="100%" variableRowHeight="true" wordWrap="true" itemClick="getItemDetailsFromfavorite(),setHistoryFromFavorite()" dropEnabled="true">
</mx:List>
</mx:Canvas>
<mx:Canvas label="表示履歴" width="100%" height="100%">
<mx:List id="histotyList" dataProvider="{historyCollection}" labelField="TitleName" width="198" height="100%" variableRowHeight="true" wordWrap="true" itemClick="getItemDetailsFromHistory()">
</mx:List>
</mx:Canvas>
</mx:Accordion>
</mx:Panel>
</mx:AddChild>
<mx:SetProperty target="{resultPanel}" name="height" value="670"/>
<mx:SetProperty target="{vboxRight}" name="height" value="590"/>
<mx:AddChild target="{itemThumbnailList}" position="before">
<mx:Canvas id="detailCanvas" width="100%" height="100%" >
<mx:HBox id="itemDetailsBox" height="100%" verticalAlign="middle">
<mx:VBox id="detailImageBox" height="200" width="180" verticalAlign="middle" horizontalAlign="center">
<mx:Spacer/>
<mx:Image id="detailImage" y="20" width="180" horizontalAlign="center" showBusyCursor="true"/>
<mx:Spacer/>
<mx:Button id="itemLinkButton" label="Amazonの詳細ページへ" textAlign="center" click="gotoAmazon()" />
</mx:VBox>
<mx:VBox id="detailTextBox" height="100%" width="100%" >
<mx:Spacer height="10"/>
<mx:HBox width="100%">
<mx:Label text="商品名" width="50" fontSize="14" fontFamily="_ゴシック"/>
<mx:Text id="titleText" width="300" autoSize="true" fontSize="16" fontFamily="_ゴシック" fontWeight="bold"/>
</mx:HBox>
<mx:Spacer height="5"/>
<mx:HBox width="100%">
<mx:Label text="価 格" width="50" fontSize="14" fontFamily="_ゴシック"/>
<mx:Text id="priceText" width="300" fontSize="16" fontFamily="_ゴシック" fontWeight="bold"/>
</mx:HBox>
<mx:Spacer height="5"/>
<mx:TextArea id="reviewText" editable="false" width="95%" height="160" fontSize="12" fontFamily="_ゴシック" paddingLeft="5" paddingRight="5"/>
</mx:VBox>
</mx:HBox>
</mx:Canvas>
</mx:AddChild>
<mx:RemoveChild child="{backButton}"/>
<mx:RemoveChild child="{nextPageButton}"/>
<mx:AddChild target="{resultPanelControlBar}" position="lastChild">
<mx:Button label="検索結果を表示" id="showResultButton" fontFamily="_ゴシック" fontSize="12" click="itemSearch()"/>
</mx:AddChild>
</mx:State>
<mx:State name="moveItemListState" basedOn="showItemDetailsState" enterState="currentState=('showItemDetailsState')">
<mx:SetProperty target="{itemThumbnailList}" name="y" value="400"/>
<mx:RemoveChild child="{detailCanvas}"/>
<mx:AddChild target="{itemThumbnailList}" position="before">
<mx:Spacer height="290" width="100%"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:transitions>
<mx:Transition id="searchTransition" fromState="*" toState="searchResultState">
<mx:Resize target="{searchPanel}" duration="800" />
</mx:Transition>
<mx:Transition id="moveDownTransition" fromState="searchResultState" toState="moveItemListState">
<mx:Move target="{itemThumbnailList}" duration="800" />
</mx:Transition>
</mx:transitions>
<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";
private var _panelFlag:String="";
private var _penalLinkURL:String="";
[Bindable]
private var thumbnailCollection:ArrayCollection = new ArrayCollection();
[Bindable]
private var historyCollection:ArrayCollection = new ArrayCollection();
[Bindable]
private var favoriteCollection:ArrayCollection = new ArrayCollection();
Security.loadPolicyFile("http://xml.amazon.com/crossdomain.xml");
[Embed(source="images/no_image_mm.gif")]
public var noImage_mm:Class;
private var _paging_number:Number=0;
private function itemSearch():void{
_paging_number=1;
historyCollection.removeAll();
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 pageSearch(inNum:Number):void{
_paging_number=_paging_number+inNum;
if(_paging_number<1){
_paging_number=1;
}
if(_paging_number>Number(itemSearchSrv.result.Items.TotalPages)){
_paging_number=Number(itemSearchSrv.result.Items.TotalPages);
}
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,ItemPage:String(_paging_number)};
itemSearchSrv.send(sendObject);
}
private function itemSearchResultHandler(event:ResultEvent):void{
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 itemAmazonURL:String=currentItemsObj.DetailPageURL;
var itemASIN:String=currentItemsObj.ASIN;
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;
}
if(itemSmallImageURL==""){
itemSmallImageURL="images/no_image_ss.gif";
}
var itemViewObj:Object={AmazonURL:itemAmazonURL , ASIN:itemASIN , TitleName:itemTitle , imageURL:itemSmallImageURL , PriceAmount:itemPrice};
thumbnailCollection.addItem(itemViewObj);
}
}
private function requestFaultHandler(event:FaultEvent):void{
Alert.show(event.fault.faultstring, "Error requesting data");
}
private function getItemDetails():void{
if(itemThumbnailList.selectedItem==null){
return;
}
_panelFlag="default";
_penalLinkURL=itemThumbnailList.selectedItem.AmazonURL;
var operation_str:String="ItemLookup";
var itemId_str:String=itemThumbnailList.selectedItem.ASIN;
var responseGroup_str:String="Medium,Similarities,Accessories";
var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str ,
ItemId:itemId_str ,ResponseGroup:responseGroup_str};
itemDetailsSrv.send(sendObject);
}
private function setHistoryFromThumbnail():void{
if(itemThumbnailList.selectedItem==null){
return;
}
var currentItem:Object=itemThumbnailList.selectedItem;
historyCollection.addItemAt(currentItem,0);
}
private function setHistoryFromFavorite():void{
if(favoriteList.selectedItem==null){
return;
}
var currentItem:Object=favoriteList.selectedItem;
historyCollection.addItemAt(currentItem,0);
}
private function getItemDetailsFromHistory():void{
if(histotyList.selectedItem==null){
return;
}
_panelFlag="history";
var operation_str:String="ItemLookup";
var itemId_str:String=histotyList.selectedItem.ASIN;
var responseGroup_str:String="Medium,Similarities,Accessories";
var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str ,
ItemId:itemId_str ,ResponseGroup:responseGroup_str};
itemDetailsSrv.send(sendObject);
}
private function getItemDetailsFromfavorite():void{
if(favoriteList.selectedItem==null){
return;
}
_panelFlag="favorite";
var operation_str:String="ItemLookup";
var itemId_str:String=favoriteList.selectedItem.ASIN;
var responseGroup_str:String="Medium,Similarities,Accessories";
var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , ItemId:itemId_str ,ResponseGroup:responseGroup_str};
itemDetailsSrv.send(sendObject);
}
private function showItemDetailsResultHandler(event:ResultEvent):void{
var _itemObj:Object=event.result;
var itemMediumImageURL:String = _itemObj.Items.Item.MediumImage.URL;
var itemEditorialReview:String = _itemObj.Items.Item.EditorialReviews.EditorialReview.Content;
var similarItemXmlList:XMLList = _itemObj.Items.Item.SimilarProducts.SimilarProduct;
var similarItemListArray:Array=[];
for( var i:Number=0;i<similarItemXmlList.length();i++ ){
var itemSimilarASIN:String=_itemObj.Items.Item.SimilarProducts.SimilarProduct[i].ASIN;
similarItemListArray.push(itemSimilarASIN);
}
var itemAccessoryItemXmlList:XMLList = _itemObj.Items.Item.Accessories.Accessory;
var accessoryItemListArray:Array=[];
for( var i:Number=0;i<itemAccessoryItemXmlList.length();i++ ){
var itemAccessoryASIN:String=_itemObj.Items.Item.Accessories.Accessory[i].ASIN;
accessoryItemListArray.push(itemAccessoryASIN);
}
var getItemArray:Array=similarItemListArray.concat(accessoryItemListArray);
getItemArray.splice(10);
if(getItemArray.length>0){
itemSimilarSearch(getItemArray);
}
if(itemMediumImageURL==""){
detailImage.source=noImage_mm;
detailImage.load();
}else{
detailImage.source=itemMediumImageURL;
detailImage.load();
}
if(_panelFlag=="history"){
titleText.text=histotyList.selectedItem.TitleName;
priceText.text=histotyList.selectedItem.PriceAmount;
}else if(_panelFlag=="favorite"){
titleText.text=favoriteList.selectedItem.TitleName;
priceText.text=favoriteList.selectedItem.PriceAmount;
}else if(_panelFlag=="default"){
titleText.text=itemThumbnailList.selectedItem.TitleName;
priceText.text=itemThumbnailList.selectedItem.PriceAmount;
}
if(itemEditorialReview==""){
itemEditorialReview="レビュー情報は含まれていませんでした。";
}
reviewText.htmlText=itemEditorialReview;
}
private function itemSimilarSearch(inArray:Array):void{
var operation_str:String="ItemLookup";
var idType_str:String="ASIN";
var itemID_str:String=inArray.toString();
var responseGroup_str:String="Medium";
var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str ,
IdType:idType_str, ItemId:itemID_str ,ResponseGroup:responseGroup_str};
itemSearchSrv.send(sendObject);
}
private function gotoAmazon():void{
if(_panelFlag=="history"){
navigateToURL(new URLRequest(histotyList.selectedItem.AmazonURL));
}else if(_panelFlag=="favorite"){
navigateToURL(new URLRequest(favoriteList.selectedItem.AmazonURL));
}else if(_panelFlag=="default"){
navigateToURL(new URLRequest(_penalLinkURL));
}
}
]]>
</mx:Script>
</mx:Application>