| 1 | <?xml version="1.0" encoding="utf-8"?> |
|---|
| 2 | <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();"> |
|---|
| 3 | <mx:HBox styleName="keyword"> |
|---|
| 4 | <mx:HBox enabled="true" id="searchbox"> |
|---|
| 5 | <mx:TextInput id="keyword" styleName="input" focusIn="onSearchFocus();" focusOut="onSearchLeave();" /> |
|---|
| 6 | <mx:Button id="keywordSubmit" label="Search" click="flickrStart();" /> |
|---|
| 7 | </mx:HBox> |
|---|
| 8 | <mx:Label id="imageUrl" selectable="true" /> |
|---|
| 9 | <mx:Label id="permalink" selectable="true" /> |
|---|
| 10 | </mx:HBox> |
|---|
| 11 | |
|---|
| 12 | <mx:Script> |
|---|
| 13 | <![CDATA[ |
|---|
| 14 | import com.adobe.webapis.flickr.*; |
|---|
| 15 | import com.adobe.webapis.flickr.events.*; |
|---|
| 16 | import com.adobe.webapis.flickr.methodgroups.*; |
|---|
| 17 | import net.suztomo.FPazzle.*; |
|---|
| 18 | import net.suztomo.FPazzle.event.*; |
|---|
| 19 | |
|---|
| 20 | import flash.events.*; |
|---|
| 21 | import flash.system.*; |
|---|
| 22 | |
|---|
| 23 | import mx.core.UIComponent; |
|---|
| 24 | import mx.managers.*; |
|---|
| 25 | import mx.controls.*; |
|---|
| 26 | |
|---|
| 27 | private var fls:FlickrService; |
|---|
| 28 | private var loader:Loader; |
|---|
| 29 | private var photo:Photos; |
|---|
| 30 | private var img:BitmapData; |
|---|
| 31 | private var flc:FlickrConnector; |
|---|
| 32 | private var targetUrl:String; |
|---|
| 33 | private var bgImage:MiniImage; |
|---|
| 34 | private var bgImages:Array; |
|---|
| 35 | private static var defaultInputText:String = "Enter Keyword"; |
|---|
| 36 | |
|---|
| 37 | public static var container:UIComponent; |
|---|
| 38 | |
|---|
| 39 | private var board:FBoard; |
|---|
| 40 | public function init():void { |
|---|
| 41 | flc = new FlickrConnector(); |
|---|
| 42 | Security.loadPolicyFile("http://farm1.static.flickr.com/crossdomain.xml"); |
|---|
| 43 | Security.loadPolicyFile("http://farm2.static.flickr.com/crossdomain.xml"); |
|---|
| 44 | Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml"); |
|---|
| 45 | Security.loadPolicyFile("http://farm4.static.flickr.com/crossdomain.xml"); |
|---|
| 46 | |
|---|
| 47 | addEventListener(KeyboardEvent.KEY_DOWN, onPressKey); |
|---|
| 48 | keyword.text = defaultInputText; |
|---|
| 49 | if (Application.application.parameters.url && Application.application.parameters.url.length > 5) { |
|---|
| 50 | targetUrl = Application.application.parameters.url |
|---|
| 51 | imageUrl.htmlText = '<a target="_blank" href="'+targetUrl+'">Flickr Photo Page</a>'; |
|---|
| 52 | startLoadImage(); |
|---|
| 53 | } |
|---|
| 54 | container = new UIComponent(); |
|---|
| 55 | addChild(container); |
|---|
| 56 | |
|---|
| 57 | bgImages = new Array(); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public function flickrStart():void { |
|---|
| 61 | if (keyword.text.length < 5) { |
|---|
| 62 | Alert.show("Please Input 5 or more charactors word", "Too short keyword"); |
|---|
| 63 | return; |
|---|
| 64 | } |
|---|
| 65 | var word:String = keyword.text; |
|---|
| 66 | flc.setOnComplete(onFlickrImageComplete); |
|---|
| 67 | flc.loadImage(word, 0); |
|---|
| 68 | flc.addEventListener(FlickrConnector.NOT_FOUND, onNotFound); |
|---|
| 69 | searchbox.enabled = false; |
|---|
| 70 | CursorManager.setBusyCursor(); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | public function onFlickrImageComplete(event:Event): void |
|---|
| 74 | { |
|---|
| 75 | img = event.target.content.bitmapData; |
|---|
| 76 | board = new FBoard(2, 2, img); |
|---|
| 77 | board.addEventListener(FBoard.BOARD_COMPLETE, onBoardComplete); |
|---|
| 78 | addChild(board); |
|---|
| 79 | board.photo = flc.tmpPhoto; |
|---|
| 80 | targetUrl = "http://flickr.com/photos/"+board.photo.ownerId+"/"+board.photo.id; |
|---|
| 81 | imageUrl.htmlText = '<font color="#61D2FF"><a target="_blank" href="'+targetUrl+'" >'+ 'View current photo on Flickr</a></font>'; |
|---|
| 82 | /* permalink.htmlText = ' <font color="#61D2FF"><a target="_blank" href="http://suztomo.net/fp/?url='+board.photo.url+'">' |
|---|
| 83 | + 'Permalink to Pazzle</a></font>';*/ |
|---|
| 84 | board.createPieces(); |
|---|
| 85 | |
|---|
| 86 | for each(var i:MiniImage in bgImages) { |
|---|
| 87 | i.down(img.height*0.6); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | bgImage = new MiniImage(img); |
|---|
| 91 | bgImages.push(bgImage); |
|---|
| 92 | bgImage.bitmapData = event.target.content.bitmapData; |
|---|
| 93 | bgImage.scaleX = 0.6; |
|---|
| 94 | bgImage.scaleY = 0.6; |
|---|
| 95 | bgImage.x = 50; |
|---|
| 96 | bgImage.y = 100; |
|---|
| 97 | if (i != null) { |
|---|
| 98 | i.addCustomEventListener("moved", onMiniImageMoved); |
|---|
| 99 | } else { |
|---|
| 100 | container.addChild(bgImage); |
|---|
| 101 | bgImage.emerge(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | CursorManager.removeBusyCursor(); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | private function onMiniImageMoved(e:Event):void |
|---|
| 108 | { |
|---|
| 109 | bgImage.alpha = 0; |
|---|
| 110 | container.addChild(bgImage); |
|---|
| 111 | bgImage.emerge(); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | public function startLoadImage():void |
|---|
| 115 | { |
|---|
| 116 | searchbox.enabled = false; |
|---|
| 117 | CursorManager.setBusyCursor(); |
|---|
| 118 | loader = new Loader(); |
|---|
| 119 | loader.addEventListener(Event.COMPLETE, onLoadTargetImage); |
|---|
| 120 | loader.load(new URLRequest(targetUrl), new LoaderContext(true)); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | private function onLoadTargetImage(event:Event):void |
|---|
| 124 | { |
|---|
| 125 | trace(event.target.bitmapData); |
|---|
| 126 | board = new FBoard(3, 3, event.target.bitmapData); |
|---|
| 127 | addChild(board); |
|---|
| 128 | board.createPieces(); |
|---|
| 129 | permalink.htmlText = ' <font color="#61D2FF"><a target="_blank" href="http://suztomo.net/fp/?url='+targetUrl+'">' |
|---|
| 130 | + 'Permalink to Pazzle</a></font>'; |
|---|
| 131 | CursorManager.removeBusyCursor(); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | private function onBoardComplete(event:FPazzleEvent):void |
|---|
| 135 | { |
|---|
| 136 | searchbox.enabled = true; |
|---|
| 137 | board.showPhotoInfo(); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | private function onNotFound(event:Event):void |
|---|
| 141 | { |
|---|
| 142 | Alert.show("No photo found by the keyword", "Photo Not Found"); |
|---|
| 143 | searchbox.enabled = true; |
|---|
| 144 | CursorManager.removeBusyCursor(); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | private function onPressKey(event:KeyboardEvent):void |
|---|
| 148 | { |
|---|
| 149 | if (event.keyCode == 13 && searchbox.enabled) keywordSubmit.dispatchEvent(new MouseEvent(MouseEvent.CLICK)); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | private function onSearchFocus():void |
|---|
| 153 | { |
|---|
| 154 | if (keyword.text == defaultInputText) keyword.text = ""; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | private function onSearchLeave():void |
|---|
| 158 | { |
|---|
| 159 | if (keyword.text.length < 2) |
|---|
| 160 | keyword.text=defaultInputText; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | ]]> |
|---|
| 165 | </mx:Script> |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | <mx:Style source="FPazzle.css"/> |
|---|
| 169 | </mx:Application> |
|---|