Guest User

Untitled

a guest
Jul 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. //THIS IS IN THE FLA.
  2.  
  3. import PhotoGallery; //import the new PhotoGallery class.
  4.  
  5. var gal:PhotoGallery = new PhotoGallery("pics.xml");
  6. gal.x = gal.y = 1; // set it's position on the stage
  7. addChild(gal); // add to the stage
  8.  
  9. stop(); // stop main Timeline
  10.  
  11.  
  12. //PhotoGallery.as
  13.  
  14. package {
  15. import fl.containers.UILoader;
  16. import caurina.transitions.*;
  17. import flash.events.*;
  18. import flash.display.MovieClip;
  19. import flash.display.Sprite;
  20. import flash.net.URLLoader;
  21. import flash.net.URLRequest;
  22.  
  23. public class PhotoGallery extends MovieClip {
  24.  
  25. //---------loading the external xml file-------
  26. var urlRequest:URLRequest;
  27. var urlLoader:URLLoader;
  28. var myXML:XML;
  29. var xmlList:XMLList;
  30. //--------holds the thumbnail objects-------
  31. var thmbArray:Array;
  32. //--------represents the number of rows-------
  33. var nrRows:uint;
  34. //-------represents the container of our gallery
  35. var sprite:Sprite;
  36. var thumb:Thumbnail;
  37. //-------- the thumbnails container-------
  38. var thumbsHolder:Sprite;
  39. //-------- the photoLoader container-------
  40. var loaderHolder:Sprite;
  41. //-------- loads the big photo-------
  42. var photoLoader:UILoader;
  43. //-------loads the caption------
  44. private var cap:Caption;
  45.  
  46. public function init():void {
  47. //---------loading the external xml file-------
  48. urlRequest=new URLRequest("pics.xml");
  49. urlLoader = new URLLoader();
  50. myXML = new XML();
  51. myXML.ignoreWhitespace=true;
  52. myXML.prettyPrinting=false;
  53. urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
  54. urlLoader.load(urlRequest);
  55. //--------holds the thumbnail objects-------
  56. thmbArray = new Array();
  57. //--------represents the number of rows-------
  58. nrRows=1;
  59. //-------represents the container of our gallery
  60. sprite = new MovieClip();
  61. sprite.x=sprite.y-0;
  62. addChild(sprite);
  63.  
  64. //-------- the thumbnails container-------
  65. thumbsHolder = new Sprite();
  66. sprite.addChild(thumbsHolder);
  67. //-------- the photoLoader container-------
  68. loaderHolder = new Sprite();
  69. loaderHolder.graphics.beginFill(0xffffff,1);
  70. loaderHolder.graphics.drawRect(0,0,680,385);
  71. loaderHolder.graphics.endFill();
  72. loaderHolder.x=20;//position off to the right
  73. loaderHolder.y=-1000;
  74. sprite.addChild(loaderHolder);
  75. //-------- loads the big photo-------
  76. photoLoader = new UILoader();
  77. photoLoader.width=500;
  78. photoLoader.height=365;
  79. photoLoader.y=10;
  80. photoLoader.x=10;
  81. photoLoader.buttonMode=true;
  82. photoLoader.addEventListener(MouseEvent.CLICK,onClickBack);
  83. loaderHolder.addChild(photoLoader);
  84. var prev:PrevNextButton = new PrevNextButton();
  85. var next:PrevNextButton = new PrevNextButton();
  86.  
  87. prev.addEventListener(MouseEvent.CLICK, function() { moveIt(-1); });
  88. prev.buttonMode = true;
  89. prev.x = 100;
  90. prev.y = 250;
  91. prev.scaleX = prev.scaleY = 3;
  92. addChild(prev);
  93.  
  94. next.addEventListener(MouseEvent.CLICK, function() { moveIt(1); });
  95. next.buttonMode = true;
  96. next.x = 500;
  97. next.y = 250;
  98. next.scaleX = next.scaleY = 3;
  99. addChild(next);
  100. photoLoader.addEventListener(MouseEvent.CLICK, onClickBack);
  101. }
  102.  
  103. /* we loop through the xml file
  104. populate the arrayURL, arrayName and position the thumbnalis*/
  105. function fileLoaded(event:Event):void {
  106. myXML=XML(event.target.data);
  107. xmlList=myXML.children();
  108. var th:Thumbnail;
  109. for (var i:int=0; i<xmlList.length(); i++) {
  110. var picURL:String=xmlList[i].url;
  111. var picName:String=xmlList[i].big_url;
  112.  
  113. th=new Thumbnail(picURL,i,picName);
  114. th.addEventListener(MouseEvent.CLICK, onClick);
  115. th.name=picName;
  116. th.buttonMode=true;
  117. if (i<nrRows) {
  118. th.y=i*125+225;
  119. th.x=75;
  120. } else {
  121. th.y=thmbArray[i-nrRows].y;
  122. th.x=thmbArray[i-nrRows].x+125;
  123. }
  124. }
  125. }
  126. //----handles the Click event added to the thumbnails--
  127. function onClick(event:MouseEvent):void {
  128. photoLoader.source=event.currentTarget.name;
  129. Tweener.addTween(thumbsHolder, {x:-650, time:1, transition:"easeInExpo"});
  130. Tweener.addTween(loaderHolder, {y:20, time:1, transition:"easeInOutCubic"});
  131. Tweener.addTween(thumbsHolder, {alpha:0, time:1, transition:"linear"});
  132. Tweener.addTween(loaderHolder, {alpha:1, time:1, transition:"linear"});
  133. }
  134. //----handles the Click event added to the photoLoader----
  135. function onClickBack(event:MouseEvent):void {
  136. Tweener.addTween(thumbsHolder, {x:0, time:1, transition:"easeInExpo"});
  137. Tweener.addTween(loaderHolder, {y:-1000, time:1, transition:"easeInOutCubic"});
  138. Tweener.addTween(thumbsHolder, {alpha:1, time:2, transition:"linear"});
  139. Tweener.addTween(loaderHolder, {alpha:0, time:2, transition:"linear"});
  140. }
  141.  
  142.         // The class contructor. Get's called everytime the
  143.         // class is created.
  144.        
  145. public function PhotoGallery(src:String):void {
  146. init();
  147. }
  148.  
  149. function moveIt(dir:int) {
  150. var offsetX:Number = thumbsHolder.x + (dir * (3 * 110));
  151. Tweener.addTween(thumbsHolder, {x:offsetX, time:1, transition:"easeOut"});
  152. }
  153.  
  154. }
  155. }
Add Comment
Please, Sign In to add comment