Posted By

adamcoulombe on 12/18/09


Tagged

image xml preloader slider multiple as3 TweenLite team2p0


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

jhoard
djmaddy
ClayVillage
davidino1978
tspitzr
burnandbass
jdsantiagojr


XML Image Slider using AS3 and Multiple Image Preloader and Tweenlite


 / Published in: ActionScript 3
 

URL: http://www.adamcoulombe.info/lab/as3/xml_slider.html

Demo:http://www.adamcoulombe.info/lab/as3/xmlslider.html FLA: http://www.adamcoulombe.info/lab/as3/xmlslider.fla

Requires Tweenlite and the multiple movieclip preloader from here: http://code.google.com/p/as3-multiple-file-preloader/

  1. import com.greensock.*; //download from http://www.greensock.com/tweenlite/
  2. import com.team2p0.*; //download from http://code.google.com/p/as3-multiple-file-preloader/
  3.  
  4.  
  5. var dimensions:Object = {width:550,height:400};
  6. var container:MovieClip = new MovieClip();
  7. addChild(container);
  8. var TOTAL_IMAGES:Number;
  9. var NUMBER_OF_IMAGES_LOADED:Number = 0;
  10. var INDEX_AT:Number = 0;
  11. container.x=0;container.y=0;
  12. var xml:XML;
  13. var xmlLoader:URLLoader = new URLLoader();
  14. xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
  15. xmlLoader.load(new URLRequest("images.xml"));
  16. var preloader:Preload;
  17. var images:Array = new Array();
  18.  
  19.  
  20. function xmlLoaded(e:Event):void {
  21. xml = new XML(e.target.data);
  22. TOTAL_IMAGES = xml.image.length();
  23. for (var i in xml.image){ images.push(xml.image[i]); }
  24. preloader = new Preload(images); // instantiate and add the files to be preloaded as an array
  25. preloader.addEventListener("preloadProgress", onPreloadProgress);
  26. preloader.addEventListener("preloadComplete", onPreloadComplete);
  27.  
  28. }
  29.  
  30. function onPreloadComplete(e:Event):void {
  31. for(var i in xml.image){
  32. var image = preloader.objects[i];
  33. //imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
  34. container["container"+i] = new MovieClip();
  35. container["container"+i].addChild(image);
  36. container["container"+i].x = i * dimensions.width;
  37. var imageMask:Sprite = new Sprite();
  38. imageMask.graphics.beginFill(0x000000);
  39. imageMask.graphics.drawRect(0, 0, dimensions.width, dimensions.height);
  40. imageMask.graphics.endFill();
  41. container.addChild(container["container"+i]);
  42. container["container"+i].addChild(imageMask);
  43. image.mask = imageMask;
  44. }
  45. imagesReady();
  46. }
  47.  
  48. function onPreloadProgress(e:Event):void {
  49. }
  50.  
  51. /*
  52. function imageLoaded(e:Event):void {
  53. NUMBER_OF_IMAGES_LOADED++;
  54. if( NUMBER_OF_IMAGES_LOADED == TOTAL_IMAGES){
  55. imagesReady();
  56. }
  57. }*/
  58.  
  59. function imagesReady():void {
  60. TweenLite.from(container, 0.5, {x:dimensions.width*(TOTAL_IMAGES-1)*-1, onComplete:function(){
  61. INDEX_AT = 0;
  62. stage.addEventListener(MouseEvent.MOUSE_UP, mouseClicked);
  63. }});
  64. }
  65.  
  66. function mouseClicked(e:MouseEvent):void {
  67. stage.removeEventListener(MouseEvent.MOUSE_UP, mouseClicked);
  68. if(INDEX_AT<TOTAL_IMAGES-1){
  69. TweenLite.to(container, 0.5, {x:container.x-dimensions.width, onComplete:function(){
  70. INDEX_AT++;
  71. stage.addEventListener(MouseEvent.MOUSE_UP, mouseClicked);
  72. }});
  73. }else{
  74. TweenLite.to(container, 0.5, {x:0, onComplete:function(){
  75. INDEX_AT = 0;
  76. stage.addEventListener(MouseEvent.MOUSE_UP, mouseClicked);
  77. }});
  78. }
  79. }

Report this snippet  

You need to login to post a comment.