:: Catégories

  • actionscript 3
  • Air
  • Flash
  • Flex
  • molehill
  • Non classé
  • papervision
  • Web

:: Derniers articles.

  • Nouveau Android Flash Game : Kick The Ducks !
  • Démo – Client FTP en Flex
  • Démo Molehill – particules
  • [TUTO] AS3 + APPARAT / TDSI, accélérez vos projets !
  • [FIXED] SecurityError: fileWriteResource
  • [Tutorial] Techniques d’optimisations en AS3
  • [Tutorial] Un client FTP en AS3 sous RoboLegs + SwfStudio – partie 2
  • [Tutorial] Un client FTP en AS3 sous RoboLegs + SwfStudio – partie 1

:: Tags

  • 3d actionscript3 ACTUce android as3 client code demo ducks Flash Flex flexunit framework ftp game jeux kick molehill optimisations particules robotlegs swfStudio tests unitaires the

:: Sites Exoa

  • Home
  • actionscript 3
  • Air
  • Flash
  • Flex
  • molehill
  • Non classé
  • papervision
  • Web

exoa labs

[TUTORIAL] Un preloader d’images animé en Flash

Aucun commentaire - fév 26th, 2010 - Flash, actionscript 3

Voici comment rapidement avoir un effet "lightbox" en flash:
shadematerial











classe du chargeur d'image :

  1.  
  2. package {
  3. import flash.net.URLRequest;
  4. import flash.display.*;
  5. import flash.events.*;
  6. import SliderClip;
  7. public class ImageLoader extends MovieClip
  8. {
  9.  
  10. private var clip:SliderClip;
  11. private var url:String;
  12. private var loader:Loader;
  13.  
  14. private var targetX:Number=100;
  15. private var targetY:Number=100;
  16. private var speed:Number=2;
  17. public function ImageLoader(purl,tx,ty,s)
  18. {
  19. targetX = tx,
  20. targetY = ty;
  21.  
  22. speed = s;
  23. url=purl
  24. clip = new SliderClip();
  25.  
  26. addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)
  27. }
  28. private function onAddedToStage(e:Event)
  29. {
  30. loader = new Loader();
  31. configureListeners(loader.contentLoaderInfo);
  32. var request:URLRequest = new URLRequest(url);
  33. loader.load(request);
  34. //addChild(loader);
  35. stage.addEventListener(Event.RESIZE, onResize);
  36. }
  37. private function onResize(e:Event)
  38. {
  39. clip.x = stage.stageWidth / 2;
  40. clip.y = stage.stageHeight / 2;
  41. loader.x = clip.x - clip.width / 2 + 5;
  42. loader.y = clip.y - clip.height / 2 + 5;
  43. }
  44. private function configureListeners(dispatcher:IEventDispatcher):void {
  45. dispatcher.addEventListener(Event.COMPLETE, completeHandler);
  46. dispatcher.addEventListener(Event.INIT, initHandler);
  47. dispatcher.addEventListener(IOErrorEvent.IO_ERROR, error);
  48. dispatcher.addEventListener(Event.OPEN, openHandler);
  49. dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  50.  
  51. }
  52.  
  53. private function completeHandler(event:Event):void {
  54. trace("completeHandler: " + event);
  55. }
  56. private function initHandler(event:Event):void {
  57. //trace("initHandler: " + event);
  58. //trace(event.target.width)
  59. addChild(clip);
  60. clip.goTo(targetX,targetY,event.target.width+10,event.target.height+10,speed);
  61. clip.addEventListener(Event.COMPLETE,loadContent)
  62. }
  63. private function loadContent(e:Event)
  64. {
  65. addChild(loader)
  66. loader.x = clip.x - clip.width / 2 + 5;
  67. loader.y = clip.y - clip.height / 2 + 5;
  68. }
  69. private function error(event:*):void {
  70. trace("Error: " + event);
  71. }
  72.  
  73. private function openHandler(event:Event):void {
  74. trace("openHandler: " + event);
  75. }
  76.  
  77. private function progressHandler(event:ProgressEvent):void {
  78. trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
  79. }
  80.  
  81. }
  82.  
  83. }

La classe qui gère le slider :

  1.  
  2. package {
  3. import flash.display.*;
  4. import flash.events.Event;
  5. import flash.filters.DropShadowFilter;
  6. public class SliderClip extends MovieClip
  7. {
  8. public static const PLACED:String = "PLACED";
  9. private var targetX:Number=100;
  10. private var targetY:Number=100;
  11. private var targetWidth:Number=100;
  12. private var targetHeight:Number=100;
  13. private var speed:Number=2;
  14. public function SliderClip()
  15. {
  16.  
  17. //new DropShadowFilter(distance,angle, color,alpha,blurX,blurY,strength,quality,inner,knockout);
  18. var shadow=new DropShadowFilter(0, 45, 0x000000, 1, 13, 13, 0.7);
  19. this.filters = [shadow];
  20. this.alpha = 0.7;
  21. }
  22. public function goTo(ptargetX, ptargetY, ptargetWidth, ptargetHeight, pspeed)
  23. {
  24. targetX = ptargetX;
  25. targetY = ptargetY;
  26. targetWidth = ptargetWidth;
  27. targetHeight = ptargetHeight;
  28. trace(targetX,targetY,targetWidth,targetHeight,speed);
  29. this.addEventListener(Event.ENTER_FRAME,slideClip);
  30. this.gotoAndPlay(1)
  31. }
  32. public function restart()
  33. {
  34. this.addEventListener(Event.ENTER_FRAME,slideClip);
  35. this.gotoAndPlay(1)
  36. }
  37. private function slideClip(e:Event) {
  38. var clip=this;
  39. if (Math.abs(targetX-clip.x)<1) {
  40. clip.x=targetX;
  41. if (Math.abs(targetY-clip.y)<1) {
  42. clip.y=targetY;
  43. clip.removeEventListener(Event.ENTER_FRAME,slideClip);
  44. clip.addEventListener(Event.ENTER_FRAME,resizeClip);
  45. } else {
  46. clip.y = clip.y+((targetY-clip.y)/speed);
  47. }
  48. } else {
  49. clip.x = clip.x+((targetX-clip.x)/speed);
  50. }
  51.  
  52. }
  53.  
  54. private function resizeClip(e:Event) {
  55. var clip=this;
  56. if ((targetWidth>0) && (targetHeight>0)) {
  57.  
  58. if (Math.abs(targetWidth-clip.width)<1) {
  59. clip.width=targetWidth;
  60. if (Math.abs(targetHeight-clip.height)<1) {
  61. clip.height=targetHeight;
  62. trace("OK");
  63. dispatchEvent(new Event(Event.COMPLETE));
  64. clip.removeEventListener(Event.ENTER_FRAME,resizeClip);
  65. } else {
  66. clip.height = clip.height+((targetHeight-clip.height)/speed);
  67. }
  68. } else {
  69. clip.width = clip.width+((targetWidth-clip.width)/speed);
  70. }
  71. } else {
  72. clip.removeEventListener(Event.ENTER_FRAME,resizeClip);
  73. }
  74. }
  75.  
  76. }
  77.  
  78. }
  79.  

pour lancer le chargement d'une image il suffit alors d'instancier la classe ImageLoader :

  1.  
  2. var imageLoader=new ImageLoader("http://labs.exoa.fr/upload/imageLoader/image.jpg",targetX,targetY,speed);
  3.  

Les sources sont disponibles ici


    Commenter




      WORKS

    • Travaux

      PRODUCTS

    • ZenBook
    • E-ZEN Galery
    • FlashConf
    • EXOA MP3-Player

      SERVICES

    • Application Facebook
    • Advergame
    • Site Web
    • Référencement
    • Hébergement
    • Graphisme
    • Bannières & Animations
    • Application Flash

      EXOA

    • Contact
    • A propos
    • CGV
    • Mentions Légales

    © 2012 exoa labs, SIRET :517 668 349 00015 · Tél : 06.25.59.18.68 · contact@exoa.fr