<?xml version="1.0" encoding="utf-8"?> <!-- forked from felicacontest2010's FeliCa Flash Contest - FeliCa Search sample --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:VBox width="650" height="650"> <mx:Label text="【使い方】" fontSize="16"/> <mx:TextArea height="10%" width="100%" editable="false" text="ICって相性の略?(笑 恋人同士でケータイをそれぞれひとりめ、ふたりめでかざして「相性診断開始」を押してください。このページのコンテンツはシステムで生成した架空のものであり実在の人物・企業・団体等とは一切関係ありません。生成されたテキスト・画像の著作権等諸権利は全て当システム制作者にあります。"/> <mx:HBox width="100%"> <mx:Button id="button1" label="ひとりめ" fontSize="16" width="50%" click="button1Click();"/> <mx:Button id="button2" label="ふたりめ" fontSize="16" width="50%" click="button2Click();"/> </mx:HBox> <mx:HBox width="100%"> <mx:TextInput id="textInput1" text="Sony" editable="false" width="50%"/> <mx:TextInput id="textInput2" text="FeliCa" editable="false" width="50%"/> </mx:HBox> <mx:Button id="button3" label="相性診断開始" fontSize="16" width="100%" click="button3Click();"/> <mx:HBox width="100%" height="50%" horizontalGap="0"> <mx:Image id="image1" width="60%" height="100%" source="http://maker.usoko.jp/nounai_ai/img/Sony/FeliCa.gif"/> <mx:Image id="image2" width="40%" height="100%" source="http://nounaimaker.net/date/img/Sony/FeliCa.gif"/> </mx:HBox> <mx:TextArea width="100%" height="15%" id="textArea1" editable="false"/> <mx:LinkButton width="100%" label="脳内相性メーカー" textDecoration="underline" color="#0B333C" click="OpenURL();"/> </mx:VBox> <mx:Script> <![CDATA[ // イベント概要,エントリー規約をご確認ください // http://wonderfl.net/event/felica // see http://wonderfl.net/event/felica for contest regulation, only in Japanese for now, sorry // copyright sony corp. all rights reserved. // copied from http://www.felicalauncher.com/sdk4air/#menu_02 with permission :-) import com.sony.jp.felica.FeliCaControl; import com.sony.jp.felica.FeliCaSessionRequest; import com.sony.jp.felica.FeliCaSessionResponse; import com.sony.jp.felica.FeliCaOpenReaderWriterAutoRequest; import com.sony.jp.felica.FeliCaOpenReaderWriterAutoResponse; import com.sony.jp.felica.FeliCaPollingAndGetCardInformationRequest; import com.sony.jp.felica.FeliCaPollingAndGetCardInformationResponse; import com.sony.jp.felica.FeliCaCloseReaderWriterRequest; import com.sony.jp.felica.FeliCaCloseReaderWriterResponse; import com.sony.jp.felica.event.OpenStatusEvent; import com.sony.jp.felica.event.FeliCaStatusEvent; import com.sony.jp.felica.error.FeliCaAccessError; import flash.net.navigateToURL; import mx.controls.Alert; // FeliCaProxy との通信を行うコントロールクラス private var fc:FeliCaControl = new FeliCaControl(); // リンクド取得(脳内メーカー) private static const URL_USOKO_NOUNAI_AI:String = "http://maker.usoko.jp/nounai_ai/"; private static const URL_USOKO_NOUNAI_AI_IMAGE:String = "http://maker.usoko.jp/nounai_ai/img/$id1/$id2.gif"; private static const URL_USOKO_DATE_IMAGE:String = "http://nounaimaker.net/date/img/$id1/$id2.gif"; // ひとりめとふたりめ区別用(0:ひとりめ,1:ふたりめ) private var idIndex:Number = 0; // URL開く private function OpenURL():void { navigateToURL(new URLRequest(URL_USOKO_NOUNAI_AI)); } // [ひとりめ]ボタンクリック時 private function button1Click():void { button1.enabled = false; button2.enabled = false; button3.enabled = false; idIndex = 0; buttonClick(); } // [ふたりめ]ボタンクリック時 private function button2Click():void { button1.enabled = false; button2.enabled = false; button3.enabled = false; idIndex = 1; buttonClick(); } // [相性診断開始]ボタンクリック時 private function button3Click():void { button1.enabled = false; button2.enabled = false; button3.enabled = false; idIndex = 0; judge(); button1.enabled = true; button2.enabled = true; button3.enabled = true; } private function judge():void { if (textInput1.text.length == 0) { Alert.show("ひとりめを読み取ってください"); image1.source = ""; } else if (textInput2.text.length == 0) { Alert.show("ふたりめを読み取ってください"); image1.source = ""; } else { var image1URL:String = URL_USOKO_NOUNAI_AI_IMAGE.replace("$id1", textInput1.text); var image2URL:String = URL_USOKO_DATE_IMAGE.replace("$id1", textInput1.text); image1URL = image1URL.replace("$id2", textInput2.text); image2URL = image2URL.replace("$id2", textInput2.text); image1.source = image1URL; image2.source = image2URL; } } // [FeliCa を検出する] ボタンクリック時 private function buttonClick():void { // リスナー登録 fc.addEventListener(OpenStatusEvent.OPEN_COMPLETE, onOpenComplete); fc.addEventListener(OpenStatusEvent.OPEN_FAILURE, onOpenFailure); fc.addEventListener(FeliCaStatusEvent.FELICA_ACCESS_COMPLETE, onFeliCaAccessComplete); fc.addEventListener(FeliCaStatusEvent.FELICA_ACCESS_FAILURE, onFeliCaAccessFailure); fc.addEventListener(FeliCaStatusEvent.FELICA_ACCESS_PARAMETER_ERROR, onFeliCaAccessParameterError); // FeliCaProxy の認証 // wonderflの中ではこのキーをお使いください wonderfl外では使用できません // use this Standard key in wonderfl, it doesn't work outside wonderfl fc.open(10250,"__FELICA_STANDARD_KEY__", ""); } // FeliCaProxy との認証完了時 private function onOpenComplete(evt:OpenStatusEvent):void { displayMessage("FeliCaProxy との認証に成功しました。"); // リーダ/ライタの専有 RwLock(); } // FeliCaProxy との認証処理でエラー発生時 private function onOpenFailure(evt:OpenStatusEvent):void { var error:Error = evt.object as Error; displayMessage( "FeliCaProxy との相互認証に失敗しました。\n" + " ERROR : (" + error.errorID + ") " + error.message); } // FeliCa アクセス成功時 private function onFeliCaAccessComplete(evt:FeliCaStatusEvent):void { if (evt.object is FeliCaSessionResponse) { var session:FeliCaSessionResponse = evt.object as FeliCaSessionResponse; // リーダ/ライタの専有 if (session.type == FeliCaSessionResponse.HOLD) { displayMessage("リーダ/ライタの専有しました。"); // リーダ/ライタのオープンを実行 RwOpen(); } // リーダ/ライタの開放 else { displayMessage("リーダ/ライタの専有を開放しました。"); // FeliCaProxy の切断 FeliCaProxyClose(); } } else if (evt.object is FeliCaOpenReaderWriterAutoResponse) { displayMessage("リーダ/ライタのオープンに成功しました。"); // FeliCa を検出するために、Polling の実行 Polling(); } else if (evt.object is FeliCaPollingAndGetCardInformationResponse) { var response:FeliCaPollingAndGetCardInformationResponse = evt.object as FeliCaPollingAndGetCardInformationResponse; // 検出した FeliCa の情報を表示 displayMessage( "FeliCa を検出しました。\n" + " idm = " + response.idm + "\n" + " pmm = " + response.pmm); // IDmを入力 if (idIndex == 0) { textInput1.text = response.idm; } else { textInput2.text = response.idm; } // ボタンを有効 button1.enabled = true; button2.enabled = true; button3.enabled = true; // リーダ/ライタのクローズを実行 RwClose(); } else if (evt.object is FeliCaCloseReaderWriterResponse) { displayMessage("リーダ/ライタのクローズに成功しました。"); // リーダ/ライタ専有の開放 RwUnlock(); } } // FeliCa アクセス失敗時 private function onFeliCaAccessFailure(evt:FeliCaStatusEvent):void { var errorMsg:String; if (evt.object is FeliCaAccessError) { var error1:FeliCaAccessError = evt.object as FeliCaAccessError; errorMsg = " ERROR: (" + error1.errorID + ")" + error1.message + "\n" + " FeliCa Error Code (" + error1.felicaError + ")\n" + " RW Error Code (" + error1.rwError + ")\n" + " FeliCaProxy Error Code (" + error1.felicaProxyError + ")"; } else if (evt.object is Error) { var error2:Error = evt.object as Error; errorMsg = " ERROR : (" + error2.errorID + ") " + error2.message; } displayMessage("FeliCa アクセスに失敗しました\n" + errorMsg); // FeliCaProxy の切断 FeliCaProxyClose(); // ボタンを有効 button1.enabled = true; button2.enabled = true; button3.enabled = true; } // FeliCa アクセスパラメータ設定エラー発生時 private function onFeliCaAccessParameterError(evt:FeliCaStatusEvent):void { var error:Error = evt.object as Error; displayMessage( "FeliCa アクセスでパラメータエラーが発生しました。\n" + " ERROR: (" + error.errorID + ")" + error.message); // FeliCaProxy の切断 FeliCaProxyClose(); } // FeliCaProxy の切断 private function FeliCaProxyClose():void { if (fc.close() == true) { displayMessage("FeliCaProxy との接続を切断しました。"); } else { displayMessage("FeliCaProxy との接続を切断に失敗しました。"); } } // リーダ/ライタの専有を実行 private function RwLock():void { // リーダ/ライタを専有する為の情報の設定 var request:FeliCaSessionRequest = new FeliCaSessionRequest(); request.type = FeliCaSessionRequest.HOLD; // リーダ・ライタ専有要求 request.lockTimeout = 10; // 専有(Lock)するまでのタイムアウト時間(秒) request.unlockTimeout = 60; // 専有(Lock)してから開放(Unlock)するまでの見込み時間(秒) // FeliCaProxyは、このunlockTimeout時間経過した場合自動でR/W開放を行う。 // リーダ/ライタ専有を実行 fc.access(request); } // リーダ/ライタ専有の開放を実行 private function RwUnlock():void { // リーダ/ライタ専有を開放する為の情報の設定 var request:FeliCaSessionRequest = new FeliCaSessionRequest(); request.type = FeliCaSessionRequest.RELEASE; // リーダ・ライタ開放要求 // リーダ/ライタ専有開放を実行 fc.access(request); } // リーダ/ライタのオープンを実行 private function RwOpen():void { // [open_reader_writer_auto] コマンドを実行 fc.access(new FeliCaOpenReaderWriterAutoRequest()); } // FeliCa を検出するために、Polling の実行 private function Polling():void { // [polling_and_get_card_information] コマンドを実行する為の情報の設定 var request:FeliCaPollingAndGetCardInformationRequest = new FeliCaPollingAndGetCardInformationRequest(); request.systemCode = "FFFF"; // ポーリングするシステムコード // [polling_and_get_card_information] コマンドを実行 fc.access(request); } // リーダ/ライタのクローズを実行 private function RwClose():void { // [close_reader_writer] コマンドを実行 fc.access(new FeliCaCloseReaderWriterRequest()); } // メッセージの表示 private function displayMessage(msg:String):void { textArea1.text += msg; textArea1.text += "\n"; this.callLater(setScroll); // 一番下にスクロールさせる } // テキストエリアを一番下にスクロールさせる private function setScroll():void { textArea1.verticalScrollPosition = textArea1.maxVerticalScrollPosition; } ]]> </mx:Script> </mx:Application> 非接触IC(あいしょう)占い for FeliCa Flash Contest