PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/AS3/sandbox/PicasaCoverflow.as

https://github.com/paazmaya/PaazioTools
ActionScript | 818 lines | 589 code | 103 blank | 126 comment | 30 complexity | 315332827bb1d56a234a383785dfac9c MD5 | raw file
  1. /**
  2. * @mxmlc -source-path=D:/AS3libs
  3. */
  4. /**
  5. * Picasa Image thumbnail loader in a coverflow
  6. * Using the smallest size available, 75x75.
  7. *
  8. * 1. Get a list of photosets of the selected user
  9. * 2. Get the list of photos of the selected photoset
  10. * 3. Get thumbnails for each of the photos and load in the carousel
  11. * 4. Open photo in a thickbox by using ExternalInterface.
  12. */
  13. package sandbox
  14. {
  15. import flash.display.Bitmap;
  16. import flash.display.BitmapData;
  17. import flash.display.DisplayObject;
  18. import flash.display.Graphics;
  19. import flash.display.Loader;
  20. import flash.display.LoaderInfo;
  21. import flash.display.MovieClip;
  22. import flash.display.Shape;
  23. import flash.display.Sprite;
  24. import flash.display.StageAlign;
  25. import flash.display.StageQuality;
  26. import flash.display.StageScaleMode;
  27. import flash.events.*;
  28. import flash.external.ExternalInterface;
  29. import flash.filters.BitmapFilterQuality;
  30. import flash.filters.BlurFilter;
  31. import flash.geom.Point;
  32. import flash.geom.Rectangle;
  33. import flash.net.URLLoader;
  34. import flash.net.URLRequest;
  35. import flash.net.URLVariables;
  36. import flash.system.LoaderContext;
  37. import flash.text.AntiAliasType;
  38. import flash.text.TextField;
  39. import flash.text.TextFieldAutoSize;
  40. import flash.text.TextFormat;
  41. import flash.text.TextFormatAlign;
  42. import flash.text.TextLineMetrics;
  43. import flash.ui.Keyboard;
  44. import flash.ui.Mouse;
  45. import flash.utils.Timer;
  46. import org.papervision3d.cameras.Camera3D;
  47. import org.papervision3d.materials.BitmapMaterial;
  48. import org.papervision3d.objects.DisplayObject3D;
  49. import org.papervision3d.objects.Plane;
  50. import org.papervision3d.scenes.MovieScene3D;
  51. import com.greensock.TweenLite;
  52. import com.greensock.easing.*;
  53. [SWF(backgroundColor='0x042836', frameRate='60', width='800', height='150')]
  54. // 80 KB without, 207 KB with.
  55. //[Frame(factoryClass="Yooi")]
  56. public class PicasaCoverflow extends Sprite
  57. {
  58. // list of albums:
  59. // GET http://picasaweb.google.com/data/feed/api/user/olavic?kind=album&access=public
  60. // http://code.google.com/apis/picasaweb/gdata.html
  61. private var apiKey:String = "1862cc3a9e0d9d16ac3333075d29154e"; // paazio.nanbudo.fi
  62. private var apiUrl:String = "http://api.flickr.com/services/rest/";
  63. private var userId:String = "14224905@N08"; // paazio
  64. private var psetid:String = "72157602192912945"; // Kobudo - Turku (FI) - 2005/10
  65. private var thumbSide:uint = 72;
  66. private var blurMax:Number = 20;
  67. private var capBetween:Number = 16; // How much space between each photo.
  68. private var radius:Number = 940;
  69. private var viewIsSetList:Boolean = true;
  70. private var flickrBallsDirection:Number = 0.15; // Direction and speed of pixels.
  71. private var _width:Number = 800;
  72. private var _height:Number = 150;
  73. private var paazio:Sprite;
  74. private var sammakko:Sprite;
  75. private var flickrBalls:Sprite;
  76. private var container:Sprite;
  77. private var sceneMask:Shape;
  78. private var scene:MovieScene3D;
  79. private var camera:Camera3D;
  80. private var thumbArray:Array = [];
  81. private var ext:ExternalInterface;
  82. private var photoSets:XML;
  83. private var photoList:XML;
  84. private var rest:URLLoader;
  85. private var currentIndex:uint = 0;
  86. private var photos:uint = 0;
  87. private var titleField:TextField;
  88. [Embed(source='sammakko_only.swf', symbol='Froggy')] private var Froggy:Class;
  89. [Embed(source="nrkis.ttf", fontFamily="nrkis")] private var nrkis:String;
  90. /*
  91. * All small case letters needed for "paazio".
  92. * a-z U+0061-U+007A
  93. * a U+0061-U+0061
  94. * i U+0069-U+0069
  95. * o U+006F-U+006F
  96. * p U+0070-U+0070
  97. * z U+007A-U+007A
  98. */
  99. [Embed(source="papyrus.ttf", fontFamily="papyrus", unicodeRange="U+0061-U+007A")]
  100. private var papyrus:String;
  101. public function PicasaCoverflow()
  102. {
  103. stage.align = StageAlign.TOP_LEFT;
  104. stage.scaleMode = StageScaleMode.NO_SCALE;
  105. stage.quality = StageQuality.MEDIUM;
  106. stage.doubleClickEnabled = true;
  107. loaderInfo.addEventListener(Event.INIT, onInit);
  108. }
  109. public function onInit(event:Event):void
  110. {
  111. //stage.addEventListener(Event.RESIZE, onStageResize);
  112. sceneMask = new Shape();
  113. sceneMask.graphics.beginFill(0xCCCCCC);
  114. sceneMask.graphics.drawRoundRect(1, 1, _width - 2, _height - 2, 20, 20);
  115. sceneMask.graphics.endFill();
  116. addChild(sceneMask);
  117. container = new Sprite();
  118. container.x = 400;
  119. container.y = 75;
  120. container.mask = sceneMask;
  121. addChild(container);
  122. rest = new URLLoader();
  123. rest.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
  124. rest.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
  125. /*
  126. if (loaderInfo.parameters.photoset != undefined)
  127. {
  128. psetid = String(loaderInfo.parameters.photoset);
  129. }
  130. if (psetid != "undefined" && psetid != "")
  131. {
  132. loadPhotoList(psetid);
  133. titleField.text = "Loading photo set...";
  134. }
  135. else
  136. {
  137. loadSetList();
  138. titleField.text = "Loading a list of photosets...";
  139. }
  140. */
  141. //loadPhotoList(psetid);
  142. //createBorders();
  143. try
  144. {
  145. createTitleField();
  146. }
  147. catch (e:Error)
  148. {
  149. tracer("init(). createTitleField. " + e.toString());
  150. }
  151. try
  152. {
  153. createPaazio();
  154. }
  155. catch (e:Error)
  156. {
  157. tracer("init(). createPaazio. " + e.toString());
  158. }
  159. try
  160. {
  161. createSammakko();
  162. }
  163. catch (e:Error)
  164. {
  165. tracer("init(). createSammakko. " + e.toString());
  166. }
  167. try
  168. {
  169. createFlickrBalls();
  170. }
  171. catch (e:Error)
  172. {
  173. tracer("init(). createFlickrBalls. " + e.toString());
  174. }
  175. init3D();
  176. }
  177. private function init3D():void
  178. {
  179. scene = new MovieScene3D(container);
  180. // In case planes should be facing center...
  181. scene.addChild(new DisplayObject3D() , "center");
  182. camera = new Camera3D();
  183. camera.y = 100;
  184. camera.z = 1000;
  185. addEventListener(Event.ENTER_FRAME, onEnterFrame);
  186. }
  187. private function createSammakko():void
  188. {
  189. sammakko = new Froggy() as Sprite;
  190. sammakko.name = "sammakko";
  191. sammakko.x = _width - (sammakko.width + 4);
  192. sammakko.y = (_height - sammakko.height) / 2;
  193. sammakko.mouseEnabled = true;
  194. sammakko.addEventListener(MouseEvent.CLICK, onSammakkoMouse);
  195. sammakko.addEventListener(MouseEvent.DOUBLE_CLICK, onSammakkoMouse);
  196. sammakko.addEventListener(MouseEvent.MOUSE_OVER, onSammakkoMouse);
  197. sammakko.addEventListener(MouseEvent.MOUSE_OUT, onSammakkoMouse);
  198. addChild(sammakko);
  199. }
  200. private function createPaazio():void
  201. {
  202. paazio = new Sprite();
  203. paazio.name = "paazio";
  204. paazio.x = -70;
  205. paazio.y = 20;
  206. addChild(paazio);
  207. var fmt:TextFormat = new TextFormat();
  208. fmt.font = "papyrus";
  209. fmt.size = 56;
  210. fmt.bold = true;
  211. fmt.align = TextFormatAlign.LEFT;
  212. var str:String = "paazio";
  213. var num:uint = str.length;
  214. var xx:Number = 0;
  215. for (var i:uint = 0; i < num; ++i)
  216. {
  217. var txt:TextField = new TextField();
  218. txt.defaultTextFormat = fmt;
  219. txt.text = str.charAt(i);
  220. txt.autoSize = TextFieldAutoSize.RIGHT;
  221. txt.selectable = false;
  222. txt.embedFonts = true;
  223. var sp:Sprite = new Sprite();
  224. sp.name = "pz_" + i;
  225. sp.buttonMode = true;
  226. sp.mouseChildren = false;
  227. sp.addEventListener(MouseEvent.MOUSE_OVER, onPaazioMouse);
  228. sp.addEventListener(MouseEvent.MOUSE_OUT, onPaazioMouse);
  229. sp.addChild(txt);
  230. sp.x = xx + sp.width - 3;
  231. xx = sp.x;
  232. paazio.addChild(sp);
  233. }
  234. // add a feature under "p".
  235. /*
  236. var p:Sprite = paazio.getChildByName("pz_0") as Sprite;
  237. var masker:Shape = new Shape();
  238. masker.name = "masker";
  239. masker.graphics.beginFill(0x000000);
  240. masker.graphics.drawRect(0, 0, 140, 30);
  241. masker.x = p.width;
  242. fmt.size = 12;
  243. var jpTxt:TextField = new TextField();
  244. jpTxt.defaultTextFormat = fmt;
  245. jpTxt.autoSize = TextFieldAutoSize.LEFT;
  246. jpTxt.text = "Jukka Paasonen";
  247. var juga:Sprite = new Sprite();
  248. juga.addChild(jpTxt);
  249. juga.addChild(masker);
  250. juga.x = 0;
  251. juga.y = p.x + 28;
  252. // jukka.mask = masker;
  253. paazio.addChild(juga);
  254. */
  255. }
  256. private function createBorders():void
  257. {
  258. var borders:Shape = new Shape();
  259. borders.name = "borders";
  260. borders.graphics.lineStyle(1, 0x000000);
  261. borders.graphics.drawRoundRect(1, 1, _width - 2, _height - 2, 20, 20);
  262. borders.cacheAsBitmap = true;
  263. addChild(borders);
  264. }
  265. private function createFlickrBalls():void
  266. {
  267. flickrBalls = new Sprite();
  268. flickrBalls.name = "flickrBalls";
  269. flickrBalls.mouseChildren = false;
  270. flickrBalls.mouseEnabled = false;
  271. flickrBalls.visible = false;
  272. addChild(flickrBalls);
  273. var gra:Graphics;
  274. // Blue ball initially on the left side.
  275. var blue:Shape = new Shape();
  276. blue.name = "blue";
  277. blue.x = -4;
  278. flickrBalls.addChildAt(blue, 0);
  279. gra = blue.graphics;
  280. gra.beginFill(0x0063C8, 0.8);
  281. gra.drawCircle(0, 0, 4);
  282. gra.endFill();
  283. // Red ball initially on the right side.
  284. var red:Shape = new Shape();
  285. red.name = "red";
  286. red.x = 4;
  287. flickrBalls.addChildAt(red, 1);
  288. gra = red.graphics;
  289. gra.beginFill(0xFF0084, 0.8);
  290. gra.drawCircle(0, 0, 4);
  291. gra.endFill();
  292. }
  293. private function createTitleField():void
  294. {
  295. var format:TextFormat = new TextFormat();
  296. format.font = "nrkis";
  297. format.color = 0xFFFFFF;
  298. format.size = 14;
  299. titleField = new TextField();
  300. titleField.name = "titleField";
  301. titleField.defaultTextFormat = format;
  302. titleField.embedFonts = true;
  303. titleField.autoSize = TextFieldAutoSize.CENTER;
  304. titleField.antiAliasType = AntiAliasType.ADVANCED;
  305. titleField.selectable = false;
  306. titleField.background = false;
  307. titleField.border = false;
  308. titleField.mouseEnabled = false;
  309. titleField.x = _width / 2;
  310. titleField.y = 8;
  311. titleField.cacheAsBitmap = false;
  312. titleField.visible = false;
  313. addChild(titleField);
  314. }
  315. private function createCarouselItem(inx:uint):void
  316. {
  317. // Create white 1px border.
  318. var bmp:BitmapData = new BitmapData(thumbSide + 2, thumbSide + 2, true, 0x66FFFFFF);
  319. var material:BitmapMaterial = new BitmapMaterial(bmp);
  320. material.smooth = true;
  321. material.doubleSided = true;
  322. //material.oneSide = true;
  323. material.opposite = false;
  324. material.updateBitmap();
  325. var rotation:Number = (360 / photos) * (inx - 1);
  326. var radians:Number = rotation * (Math.PI / 180);
  327. var plane:Plane = new Plane(material, bmp.width, bmp.height);
  328. plane.z = radius * Math.cos(radians);
  329. plane.x = radius * Math.sin(radians);
  330. plane.y = 60;
  331. plane.name = "plane_" + inx;
  332. scene.addChild(plane);
  333. var cont:Sprite = plane.container;
  334. cont.buttonMode = true;
  335. cont.name = inx.toString();
  336. cont.buttonMode = true;
  337. cont.mouseChildren = false;
  338. cont.addEventListener(MouseEvent.CLICK, onPhotoClick);
  339. cont.addEventListener(MouseEvent.MOUSE_OVER, onPhotoOver);
  340. cont.addEventListener(MouseEvent.MOUSE_OUT, onPhotoOut);
  341. /*
  342. var blurAmount:Number = (radius - plane.z) / (radius * 2);
  343. var blur:BlurFilter = new BlurFilter((blurAmount * blurMax) / Math.abs(rotation), blurAmount * blurMax, BitmapFilterQuality.LOW);
  344. var filters:Array = [blur];
  345. cont.filters = filters;
  346. */
  347. var obj:Object = new Object();
  348. obj.plane = plane;
  349. obj.rotation = rotation;
  350. thumbArray.push(obj);
  351. }
  352. private function loadSetList():void
  353. {
  354. var variables:URLVariables = new URLVariables();
  355. variables.api_key = apiKey;
  356. variables.user_id = userId;
  357. variables.method = "flickr.photosets.getList";
  358. var request:URLRequest = new URLRequest(apiUrl);
  359. request.data = variables;
  360. rest.addEventListener(Event.COMPLETE, onSetsComplete);
  361. rest.load(request);
  362. viewIsSetList = true;
  363. resetScene();
  364. }
  365. private function loadPhotoList(setId:String):void
  366. {
  367. var variables:URLVariables = new URLVariables();
  368. variables.api_key = apiKey;
  369. variables.method = "flickr.photosets.getPhotos";
  370. variables.photoset_id = setId;
  371. var request:URLRequest = new URLRequest(apiUrl);
  372. request.data = variables;
  373. rest.addEventListener(Event.COMPLETE, onListComplete);
  374. rest.load(request);
  375. viewIsSetList = false;
  376. resetScene();
  377. }
  378. // Called when the previous item has loaded. This way only one file is loaded at a time.
  379. private function loadPhoto(inx:uint):void
  380. {
  381. var url:String = getImageUrl(inx);
  382. var request:URLRequest = new URLRequest(url);
  383. var context:LoaderContext = new LoaderContext();
  384. context.checkPolicyFile = true;
  385. var loader:Loader = new Loader();
  386. loader.name = "loader_" + inx;
  387. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPhotoComplete);
  388. loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
  389. loader.load(request, context);
  390. }
  391. private function startLoadingPhotos():void
  392. {
  393. // Recalculate dimensions.
  394. try
  395. {
  396. radius = (capBetween + thumbSide) * photos / (Math.PI * 2);
  397. camera.y = capBetween / 2 + thumbSide;
  398. camera.z = radius + 60;
  399. }
  400. catch (e:Error)
  401. {
  402. tracer("startLoadingPhotos. radius. " + e.toString());
  403. }
  404. //tracer("Photoset XML loaded. photos: " + photos + ", radius: " + radius + ", camera.y: " + camera.y + ", camera.z: " + camera.z);
  405. // Create the amount of planes needed for the photos.
  406. for (var i:uint = 0; i < photos; ++i)
  407. {
  408. createCarouselItem(i);
  409. }
  410. addEventListener(KeyboardEvent.KEY_DOWN, onArrowKeyDown);
  411. // Load the first photo.
  412. loadPhoto(currentIndex);
  413. }
  414. private function rotateAll(rotate:Number):void
  415. {
  416. var len:uint = thumbArray.length;
  417. for (var i:uint = 0; i < len; ++i)
  418. {
  419. var obj:Object = thumbArray[i] as Object;
  420. // New rotation calculation, first degrees, then radians.
  421. var rotation:Number = obj.rotation + rotate;
  422. var radians:Number = rotation * (Math.PI / 180);
  423. var rotZ:Number = radius * Math.cos(radians);
  424. var rotX:Number = radius * Math.sin(radians);
  425. TweenLite.to(obj.plane, 0.35, {z: rotZ, x: rotX, ease: Linear.easeOut});
  426. // Calculate blur according to the distance.
  427. var speedDiff:Number = Math.abs(obj.rotation - rotation) * 5;
  428. speedDiff = Math.abs(obj.rotation) * 5
  429. /*
  430. var blurAmount:Number = 0.5; //(radius - rotZ) / (radius * 2);
  431. var blur:BlurFilter = new BlurFilter((blurAmount * blurMax) + speedDiff, blurAmount * blurMax, BitmapFilterQuality.LOW);
  432. var filters:Array = [blur];
  433. obj.plane.container.filters = filters;
  434. */
  435. // Remember the new target rotation.
  436. obj.rotation = rotation;
  437. }
  438. }
  439. private function getImageUrl(inx:uint):String {
  440. /*
  441. http://www.flickr.com/services/api/misc.urls.html
  442. http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg
  443. farm-id: 1
  444. server-id: 2
  445. photo-id: 1418878
  446. secret: 1e92283336
  447. size: m
  448. */
  449. var item:XML;
  450. var url:String = "http://farm";
  451. try
  452. {
  453. if (viewIsSetList)
  454. {
  455. /*
  456. <photoset id="72157602185431246" primary="1452413827" secret="c97af94ccd" server="1171" farm="2" photos="9">
  457. <title>Kobudo - Helsinki (FI) - 2005/10/15</title>
  458. <description>Saturday morning training in Helsinki Stadion.</description>
  459. </photoset>
  460. */
  461. item = photoSets.photosets.photoset[inx] as XML;
  462. url += item.@farm.toString() + ".static.flickr.com/" + item.@server.toString() + "/" + item.@primary.toString() + "_" + item.@secret.toString();
  463. }
  464. else
  465. {
  466. /*
  467. <photo id="1453149742" secret="71e18e70ac" server="1164" farm="2" title="Kobudo2005-10-09_50" isprimary="1"/>
  468. */
  469. item = photoList.photoset.photo[inx] as XML;
  470. url += item.@farm.toString() + ".static.flickr.com/" + item.@server.toString() + "/" + item.@id.toString() + "_" + item.@secret.toString();
  471. }
  472. }
  473. catch (e:Error)
  474. {
  475. tracer("getImageUrl. inx: " + inx + ", viewIsSetList: " + viewIsSetList + ". Error: " + e.toString());
  476. }
  477. url += ".jpg";
  478. return url;
  479. }
  480. private function getTitle(inx:uint):String
  481. {
  482. var title:String;
  483. try
  484. {
  485. if (viewIsSetList)
  486. {
  487. title = photoSets.photosets.photoset[inx].title.toString();
  488. }
  489. else
  490. {
  491. title = photoList.photoset.photo[inx].@title.toString();
  492. }
  493. }
  494. catch (e:Error)
  495. {
  496. tracer("getTitle. viewIsSetList: " + viewIsSetList + ". Error: " + e.toString());
  497. }
  498. return title;
  499. }
  500. private function resetScene():void
  501. {
  502. // Reset and clean up, preparation for the new items in carousel.
  503. thumbArray = [];
  504. for (var i:uint = 0; i < photos; ++i)
  505. {
  506. scene.removeChildByName("plane_" + i);
  507. }
  508. }
  509. private function onSetsComplete(event:Event):void
  510. {
  511. Mouse.show();
  512. flickrBalls.visible = false;
  513. rest.removeEventListener(Event.COMPLETE, onSetsComplete);
  514. photoSets = new XML(rest.data);
  515. photos = photoSets.photosets.elements().length();
  516. startLoadingPhotos();
  517. }
  518. private function onListComplete(event:Event):void
  519. {
  520. rest.removeEventListener(Event.COMPLETE, onListComplete);
  521. photoList = new XML(rest.data);
  522. photos = photoList.photoset.elements().length();
  523. startLoadingPhotos();
  524. }
  525. private function onEnterFlickrBalls(event:Event):void
  526. {
  527. flickrBalls.x = mouseX;
  528. flickrBalls.y = mouseY;
  529. var blue:Shape = flickrBalls.getChildAt(0) as Shape;
  530. var red:Shape = flickrBalls.getChildAt(1) as Shape;
  531. if (flickrBallsDirection > 0)
  532. {
  533. // Blue should increase x, red should decrease x.
  534. if (blue.x >= 4)
  535. {
  536. // Limit has been reached, change direction.
  537. flickrBallsDirection *= -1;
  538. }
  539. }
  540. else
  541. {
  542. // Blue should decrease x, red should increase x.
  543. if (blue.x <= -4)
  544. {
  545. // Limit has been reached, change direction.
  546. flickrBallsDirection *= -1;
  547. }
  548. }
  549. blue.x += flickrBallsDirection;
  550. red.x += flickrBallsDirection * -1;
  551. }
  552. private function onPaazioMouse(event:MouseEvent):void
  553. {
  554. var sp:Sprite = event.target as Sprite;
  555. TweenLite.killTweensOf(sp);
  556. if (event.type == MouseEvent.MOUSE_OVER)
  557. {
  558. TweenLite.to(sp, 1, {type: "color", colorize: 0xFF0000, amount: 1, overwrite: false});
  559. TweenLite.to(sp, 1, {type: "blur", blurX: "8", blurY: "2", overwrite: false});
  560. }
  561. else if (event.type == MouseEvent.MOUSE_OUT)
  562. {
  563. }
  564. }
  565. private function onStageResize(event:Event):void
  566. {
  567. paazio.y = (stage.stageHeight - paazio.height) / 2;
  568. sammakko.x = stage.stageWidth - (sammakko.width + 4);
  569. sammakko.y = (stage.stageHeight - sammakko.height) / 2;
  570. }
  571. private function onSammakkoMouse(event:MouseEvent):void
  572. {
  573. if (event.type == MouseEvent.CLICK)
  574. {
  575. // Load a list of photosets.
  576. titleField.text = "Loading a list of photosets from Flickr...";
  577. sammakko.removeEventListener(MouseEvent.CLICK, onSammakkoMouse);
  578. sammakko.removeEventListener(MouseEvent.MOUSE_OVER, onSammakkoMouse);
  579. sammakko.removeEventListener(MouseEvent.MOUSE_OUT, onSammakkoMouse);
  580. loadSetList();
  581. }
  582. else if (event.type == MouseEvent.DOUBLE_CLICK)
  583. {
  584. //stage.displayState
  585. }
  586. else if (event.type == MouseEvent.MOUSE_OVER)
  587. {
  588. titleField.text = "Click to load my photosets from Flickr";
  589. titleField.visible = true;
  590. Mouse.hide();
  591. flickrBalls.visible = true;
  592. flickrBalls.addEventListener(Event.ENTER_FRAME, onEnterFlickrBalls);
  593. }
  594. else if (event.type == MouseEvent.MOUSE_OUT)
  595. {
  596. titleField.text = "";
  597. titleField.visible = false;
  598. Mouse.show();
  599. flickrBalls.visible = false;
  600. flickrBalls.removeEventListener(Event.ENTER_FRAME, onEnterFlickrBalls);
  601. }
  602. }
  603. private function onPhotoClick(event:MouseEvent):void
  604. {
  605. var targ:Sprite = event.target as Sprite;
  606. var inx:uint = parseInt(targ.name);
  607. // Open the photo in thickbox if the list is of photoset, else load the photoset.
  608. TweenFilterLite.to(targ, 1, {type:"Color", colorize:0xFF0000, amount:1});
  609. if (viewIsSetList)
  610. {
  611. var setId:String = photoSets.photosets.photoset[inx].@id.toString();
  612. loadPhotoList(setId);
  613. }
  614. else
  615. {
  616. // 500 bigger side photo is without additional "_x" ending.
  617. var url:String = getImageUrl(inx);
  618. var title:String = getTitle(inx);
  619. tracer("AS. url: " + url + ", title: " + title);
  620. if (ExternalInterface.available)
  621. {
  622. ExternalInterface.call("openPhotoWindow", url, title);
  623. }
  624. }
  625. }
  626. private function onPhotoOver(event:MouseEvent):void
  627. {
  628. var sp:Sprite = event.target as Sprite;
  629. var inx:uint = parseInt(sp.name);
  630. var title:String = getTitle(inx);
  631. TweenLite.to(sp, 1, {type: "color", colorize: 0xFF0000, amount: 1});
  632. titleField.text = title;
  633. titleField.visible = true;
  634. }
  635. private function onPhotoOut(event:MouseEvent):void
  636. {
  637. var sp:Sprite = event.target as Sprite;
  638. TweenLite.to(sp, 1, {type: "color", colorize: 0xFF0000, amount: 0});
  639. titleField.visible = false;
  640. }
  641. private function onPhotoComplete(event:Event):void
  642. {
  643. var loader:Loader = Loader(event.target.loader);
  644. var info:LoaderInfo = loader.contentLoaderInfo;
  645. info.removeEventListener(Event.COMPLETE, onPhotoComplete);
  646. info.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
  647. var bitmap:Bitmap = loader.content as Bitmap;
  648. var obj:Object = thumbArray[currentIndex] as Object;
  649. var plane:Plane = obj.plane as Plane;
  650. var material:BitmapMaterial = plane.material as BitmapMaterial;
  651. var bmp:BitmapData = material.bitmap as BitmapData;
  652. var rect:Rectangle = new Rectangle(0, 0, bmp.width, bmp.height);
  653. bmp.fillRect(rect, 0xFFFFFFFF);
  654. bmp.copyPixels(bitmap.bitmapData, new Rectangle(0, 0, thumbSide, thumbSide), new Point(1, 1));
  655. material.opposite = true;
  656. material.updateBitmap();
  657. // Clean up memory.
  658. loader = null;
  659. currentIndex++;
  660. // Load the next photo.
  661. if (currentIndex < photos)
  662. {
  663. loadPhoto(currentIndex);
  664. }
  665. else
  666. {
  667. // Last photo loaded.
  668. titleField.text = "";
  669. //tracer("Last photo loaded. photos: " + photos.toString() + ", currentIndex: " + currentIndex.toString());
  670. }
  671. }
  672. private function onEnterFrame(event:Event):void
  673. {
  674. scene.renderCamera(camera);
  675. }
  676. private function onMouseEnterFrame(event:Event):void
  677. {
  678. var rotate:Number = (container.mouseX / 50) / (photos / 10);
  679. rotateAll(rotate);
  680. }
  681. private function onArrowKeyDown(event:KeyboardEvent):void
  682. {
  683. var rotate:Number = 360 / photos;
  684. switch (event.keyCode)
  685. {
  686. case Keyboard.LEFT :
  687. rotateAll(-1 * rotate);
  688. break;
  689. case Keyboard.RIGHT :
  690. rotateAll(rotate);
  691. break;
  692. }
  693. }
  694. private function onIOError(event:IOErrorEvent):void
  695. {
  696. tracer("onIOError: " + event.toString());
  697. }
  698. private function onSecurityError(event:SecurityError):void
  699. {
  700. tracer("onSecurityError: " + event.toString());
  701. }
  702. private function tracer(msg:Object):void
  703. {
  704. trace(msg.toString());
  705. if (ExternalInterface.available)
  706. {
  707. ExternalInterface.call("console.log", msg.toString());
  708. }
  709. }
  710. }
  711. }