Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. package
  2. {
  3. import flash.display.MovieClip;
  4. import flash.events.Event;
  5. import flash.net.URLLoader;
  6. import flash.net.URLRequest;
  7. import flash.utils.setInterval;
  8. import flash.events.MouseEvent;
  9. import flash.geom.Rectangle;
  10. import caurina.transitions.*;
  11.  
  12. public class Miniaturki extends MovieClip
  13. {
  14. private static var mini:Array;
  15. private var minaWidth:Number = 0;
  16. private var loader:URLLoader;
  17. private var xml1:XML;
  18. private var draging:Boolean = false;
  19. public var count:Number= -1;
  20.  
  21. public function Miniaturki():void
  22. {
  23. loader = new URLLoader();
  24. loader.load(new URLRequest("obrazki.xml"));
  25. loader.addEventListener(Event.COMPLETE,onLoadXMLComplete);
  26. }
  27.  
  28. private function onLoadXMLComplete(event:Event):void
  29. {
  30. xml1 = new XML(URLLoader(event.target).data);
  31. var i:Number;
  32. mini = new Array(xml1.obrazek.length());
  33. count = xml1.obrazek.length();
  34. for (i=0;i<count;i++)
  35. {
  36. mini[i] = new Miniaturka(xml1.obrazek[i].attribute("id"),i);
  37. addChild(mini[i]);
  38. mini[i].x = i*889;
  39. trace(mini[i].width);
  40. }
  41. MovieClip(parent).nazwa.text = xml1.obrazek[0];
  42. MovieClip(parent).ilosc.text = "1/"+count;
  43. MovieClip(parent).scro.buttonMode = true;
  44. stage.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
  45. }
  46.  
  47. private function beginDrag(event:MouseEvent):void
  48. {
  49. var minScroll:Number = 0;
  50. var maxScroll:Number = MovieClip(parent).scrolbar.width - MovieClip(parent).scro.width;
  51. var bounds:Rectangle = new Rectangle(minScroll,MovieClip(parent).scro.y,maxScroll,0);
  52. MovieClip(parent).scro.startDrag(false,bounds);
  53. stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
  54. MovieClip(parent).scro.addEventListener(Event.ENTER_FRAME,checkingProgress);
  55. draging = true;
  56. }
  57.  
  58. private function endDrag(event:MouseEvent):void
  59. {
  60. MovieClip(parent).scro.stopDrag();
  61. draging = false;
  62. }
  63.  
  64. function checkingProgress(event:Event):void
  65. {
  66. var maxScroll:Number = MovieClip(parent).scrolbar.width - MovieClip(parent).scro.width;
  67. var procent:Number = MovieClip(parent).scro.x / maxScroll;
  68. if (draging)
  69. {
  70. Tweener.addTween(this,{x:(-procent*(this.width-MovieClip(parent).maska1.width)),time:1});
  71. }
  72. }
  73. }
  74. }
  75.  
  76. package
  77. {
  78. import flash.display.MovieClip;
  79. import flash.events.Event;
  80. import flash.display.Loader;
  81. import flash.net.URLRequest;
  82. import flash.display.LoaderInfo;
  83. import fl.transitions.Tween;
  84. import fl.transitions.easing.*;
  85. import flash.display.Sprite;
  86. import flash.events.MouseEvent;
  87. import flash.display.DisplayObject;
  88. import com.anttikupila.utils.JPGSizeExtractor;
  89.  
  90. public class Miniaturka extends MovieClip
  91. {
  92. private var je:JPGSizeExtractor = new JPGSizeExtractor();
  93. private var miniWidth:Number = 0;
  94. private var id:String;
  95. private var tween:Tween;
  96. private var tryb:Boolean;
  97. private var button:Sprite;
  98. private var index:Number;
  99. private var aktywna:Boolean = false;
  100. public var bLoad:Boolean = false;
  101.  
  102. public function Miniaturka(id:String, index:Number):void
  103. {
  104. var je:JPGSizeExtractor = new JPGSizeExtractor();
  105. this.id = id;
  106. this.index = index;
  107. tryb = false;
  108. var loader:Loader = new Loader();
  109. loader.load(new URLRequest("images/" + id + "m.jpg"));
  110. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, nLoadComplete);
  111. je.addEventListener( JPGSizeExtractor.PARSE_COMPLETE, sizeHandler);
  112. je.extractSize("images/" + id + "m.jpg");
  113.  
  114. function sizeHandler( e : Event ) : void
  115. {
  116. trace(je.width);
  117. }
  118.  
  119. button = new Sprite();
  120. button.graphics.beginFill(0x000000, 0);
  121. button.graphics.drawRect(0, 0, 889, 500);
  122. button.graphics.endFill();
  123. button.buttonMode = true;
  124. addChild(button);
  125. button.addEventListener(MouseEvent.MOUSE_OVER, onOver);
  126. button.addEventListener(MouseEvent.MOUSE_OUT, onOut);
  127. button.addEventListener(MouseEvent.CLICK, onClick);
  128. this.alpha = 1;
  129. }
  130.  
  131. private function nLoadComplete(event:Event):void
  132. {
  133. var loader:Loader = new Loader();
  134. loader = LoaderInfo(event.target).loader;
  135. pusty.addChild(loader);
  136. tween = new Tween(pusty, "alpha", Regular.easeOut, 0, 0.6, 2, true);
  137. bLoad = true;
  138. setStan(false);
  139. miniWidth = loader.width;
  140. pusty.alpha = 0;
  141. }
  142.  
  143. private function onOver(event:MouseEvent):void
  144. {
  145. }
  146.  
  147. private function onOut(event:MouseEvent):void
  148. {
  149. }
  150.  
  151. private function onClick(event:MouseEvent):void
  152. {
  153. }
  154. }
  155. }
  156.  
  157. public class MINIATURKI
  158. {
  159.  
  160. public function yourFunction():void
  161. {
  162. xml1 = new XML(URLLoader(event.target).data);
  163. var i:Number;
  164. var currentX:Number = 0;
  165. mini = new Array(xml1.obrazek.length());
  166. count = xml1.obrazek.length();
  167. for (i=0; i<count; i++)
  168. {
  169. mini[i] = new Miniaturka(xml1.obrazek[i].attribute("id"),i, callback);
  170. }
  171. }
  172.  
  173. //to save how many images have load complete
  174. private var loadCompleteCount:int = 0;
  175.  
  176. //save the MINIATURKA instances
  177. private var savedImgs:Array = [];
  178.  
  179. //this function will be called when the image load complete in MINIATURKA
  180. private function callback(m:MINIATURKA, index:int):void
  181. {
  182.  
  183. savedImgs[index] = m;
  184.  
  185. loadCompleteCount++;
  186.  
  187. if (loadCompleteCount == count)
  188. {
  189. //when all load complete, add them
  190. for each (var ins:MINIATURKA in savedImgs)
  191. {
  192. addChild(ins);
  193. ins.x = currentX;
  194. currentX += ins.width;
  195. }
  196. }
  197. }
  198. }
  199.  
  200. public function Miniaturka(id:String, index:Number, $callback:Function):void {
  201. //your code
  202.  
  203. imgIndex = index;
  204.  
  205. callback = $callback;
  206. }
  207.  
  208. private var imgIndex:int;
  209.  
  210. private var callback:Function;
  211.  
  212. private function nLoadComplete(event:Event):void
  213. {
  214. var loader:Loader = new Loader();
  215. loader = LoaderInfo(event.target).loader;
  216. pusty.addChild(loader);
  217. tween = new Tween(pusty, "alpha", Regular.easeOut, 0, 0.6, 2, true);
  218. bLoad = true;
  219. setStan(false);
  220. miniWidth = loader.width;
  221. pusty.alpha = 0;
  222.  
  223. createButton(loader.width);
  224. callback.apply(null, [this, imgIndex]);
  225. }
  226.  
  227. private function createButton(imgWidth:int):void
  228. {
  229. button = new Sprite();
  230. button.graphics.beginFill(0x000000, 0);
  231.  
  232. //if you draw
  233. button.graphics.drawRect(0, 0, imgWidth, 500);
  234. button.graphics.endFill();
  235. button.buttonMode = true;
  236. addChild(button);
  237. button.addEventListener(MouseEvent.MOUSE_OVER, onOver);
  238. button.addEventListener(MouseEvent.MOUSE_OUT, onOut);
  239. button.addEventListener(MouseEvent.CLICK, onClick);
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement