Développement web indépendant à Montpellier

Publié le jeudi 29 avril 2010 22:23:33

Chargement d'objets graphiques externes

L'un des principaux intérêts de flash est qu'il permet de charger tout type de contenu image et multimédia externe : jpg, png, gif, flv ou même swf. Le chargement peut être dynamique et activé après une action de l'utilisateur.

Loader et URLRequest

  • La classe Loader permet de charger des fichiers SWF ou des fichiers d’image (JPG, PNG ou GIF). L’objet d'affichage chargé est intégré en tant qu’enfant à l’objet Loader.
  • La classe URLRequest capture les informations des requêtes http ou https, ces informations sont transmises aux méthodes load() de certaines classes, notamment de la classe Loader.

Une méthode simple consiste à créer un objet Loader puis à l'afficher directement sur le clip dans lequel on le charge, de cette manière :

var _request = new URLRequest('image.png');
var _loader = new Loader();

this.addChild(_loader);
_loader.load(_request);

Téléchargement du fichier de travail

Erreur fréquente

Une erreur fréquente consiste à manipuler directement l'objet Loader à la suite de la méthode load(), afin de le redimensionner par exemple : rien ne s'affichera. En réalité cela se produit car l'on cherche à redimensionner un objet qui n'est pas encore présent sur la scène, de cette manière :

var _request = new URLRequest('image.png');
var _loader = new Loader();

this.addChild(_loader);
_loader.load(_request);

// CE CODE NE FONCTIONNE PAS :
_loader.width=400;
_loader.height=500;

Ce code ne fonctionne pas car lorsque l'on cherche à manipuler un objet qui n'est pas encore sur la scène (il faut le temps de le charger). Pour palier à ce problème, on peut utiliser les événements.

Evénements et manipulation d'objets chargés dynamiquement

Pour palier au problème du précédent paragraphe, on peut attacher un événement à l'objet Loader qui déclenchera une fonction lorsque le chargement de image.png sera terminé.

Loader dispose d'un attribut intitulé contentLoaderInfo de type LoaderInfo qui fournit des informations relatives à un fichier SWF ou à un fichier d’image (JPEG, GIF ou PNG) chargé. Les objets LoaderInfo sont disponibles pour n’importe quel objet d'affichage. C'est sur cet attribut que nous allons placer l'écouteur sur l'événement Event.COMPLETE qui correspond au moment ou l'image sera chargée :

//création de la requête
var _request = new URLRequest('image.png');
//création de l'objet Loader
var _loader = new Loader();
//On attache l'événement au LoaderInfo, lorsque que l'image est chargée, on exécute la fonction loaded
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
//On lance le chargementloader.load(_request);

//fonction loaded 
function loaded(e:Event)
{
    //ajout du loader contant l'image sur la scène
    this.addChild(_loader);
    //On redimensionne le loader
    _loader.width = 550;
    _loader.height = 400;
}

Barre de progression

Si l'on charge un contenu dont la taille est très importante, il est parfois recommandé d'afficher une barre de progression, vulgairement appelée preloader, pour cela, ajoutons un autre événement à la pile de notre LoaderInfo et un champ de texte indiquant le pourcentage de chargement.

Soit txt_pourcentage le nom d'occurrence d'un textfield :

var _request = new URLRequest('image.jpg');
var _loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
//On attache l'événement pour la progression du téléchargement
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progression);
_loader.load(_request);
function loaded(e:Event)
{
    this.addChild(_loader);
    _loader.width = 550;
    _loader.height = 400;
}
//Fonction qui affiche le pourcentage de chargement
function progression(e:Event)
{
    this.txt_pourcentage.text = (LoaderInfo(e.target).bytesLoaded/LoaderInfo(e.target).bytesTotal*100)+"%";
}

Téléchargement des fichiers de travail

Notez cet article !

  • Actuellement 0 sur 5 étoiles
  • 1
  • 2
  • 3
  • 4
  • 5

Note : 0/5 (0 notes attribuées)

Merci d'avoir participé !

Vous avez déjà noté cette page, vous ne pouvez la noter qu'une fois !

Votre note a été changée, merci de votre participation !

Bonne résolution ! j'arrête d'alourdir mes pages avec des boutons de partage, mais vous pouvez continuer de partager :-)

Commentaires

  1. ok thanks again......

  2. The author has so delightfully enraptured the consideration of crowd by this radiant blog.

  3. dfd@gmail... | اذاعة مدرسية جاهزة |

    I am thankful to the writer for forming this. Can't sit tight for another blog by this writer.

  4. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates.
    http://...-business/

  5. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.
    http://...epartment/

  6. Today the weather is quite beautiful. I like this. It makes me comfortable and works better. But I tried my best and try to finish the contest with a fierce determination to live up to the expectations of people.

  7. dsf@gmail... | 1-stop-pharmacy.com drugstore |

    In this time of false love, the creator has formed each word with everything that is in him filled it.

  8. I am impressed with this web site , really I am a big fan .

  9. Your content is nothing short of brilliant in many ways. I think this is engaging and eye-opening material. Thank you so much for caring about your content and your readers.
    http://...klater.com

  10. And he tried, trying to get away from the city where it was. I do not know what to put you in the sadness is regret or angry anxiety! He continued on to the game and enjoyed it every single day

  11. The downloader and URLRequest are very specific and detailed, easy operation, Thanks for sharing.

  12. Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me.
    http://...traveling/

  13. Mmm.. good to be here in your article or post, whatever, I think I should also work hard for my own website like I see some good and updated working in your site.http://...system.com

  14. Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.
    http://...circle.com

  15. I am impressed with this web site , really I am a big fan .
    http://...stoday.net

  16. It's surprising you aren't more popular given that you definitely possess the gift.

  17. df@gmail.com | تكلفة زراعة الشعر |

    I consider this the finest blog I have read all this hour.

  18. https://p... | https://paxforex.com/currency-trading-for-dummies |

    I recommend only good and reliable information, so see it:

  19. I'll audit this blog as An and it exhibits how much effort has been put into this.

  20. Thanks for your post! It's been a long time since I read a good article and such a meaning! I hope you will continue to write articles like these for hobbyists!

  21. The blog is sensationally wonderful. Simply cherish the way how all the written work has been put.

  22. Flawless and legendary blog, Full of sublime and virtuosic words.

  23. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.

  24. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work

  25. management associates
    I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

  26. best epil... | best epilator for facial hair |

    I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.

  27. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers.

  28. best hyal... | best hyaluronic acid moisturizer |

    I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

  29. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value. Im glad to have found this post as its such an interesting one! I am always on the lookout for quality posts and articles so i suppose im lucky to have found this! I hope you will be adding more in the future...

  30. Vigo Vide... | Vigo Video APK Download |

    Flash is need to play video and we know it while making the app better. Thanks for this article.

  31. fg@gmail.com | cryotherapy installation service new york city |

    When you begin perusing this, you can't stop without finishing it. That is the amount you get retained into it.

  32. I'm glad I found this web site, I couldn't find any knowledge on this matter prior to.Also operate a site and if you are ever interested in doing some visitor writing for me if possible feel free to let me know, i am always look for people to check out my web site.

  33. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.

  34. phenq wei... | phenq weight loss results |

    The post is written in very a good manner and it contains many useful information for me.

  35. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates.

  36. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.

  37. Ukrayna O... | Ukrayna Odessa Denizcilik Akademisi |

    Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!!

  38. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.

  39. abogados... | abogados de accidentes de auto |

    Your music is amazing. You have some very talented artists. I wish you the best of success.

  40. How to Be... | How to Better Your Business |

    Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here.

  41. Webroot.com/safe- Experience next-generation Security level with Webroot on your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.webroot.com/safe is a computer security software program for Microsoft Windows users that combine software as a service cloud protection with traditional Antivirus and anti-spyware desktop technologies. Built into the suite is a two-way firewall, a registry cleaner, Email anti-spam, secure browsing, anti-phishing and a password management service. The suite was initially released on July 26, 2010, as the 2011 version of the product.

    http://...t.com/safe

  42. LA GRANGE... | LA GRANGE POOL SERVICE |

    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.

  43. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.

  44. I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

  45. Have a natural attraction for women cosmetics and <a href="http://...;>cheap vape store</a> clothes, no more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment <a href="http://...;>cheap vape store</a>. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the <a href="http://...;>cheap e-cigarettes</a>.

  46. Your music is amazing. You have some very talented artists. I wish you the best of success.

  47. Website n... | Website nhap hang Mona Media |

    Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.

  48. Your music is amazing. You have some very talented artists. I wish you the best of success.

  49. web desig... | web design tutorial for beginners |

    I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

  50. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.

  51. Nebraska... | Nebraska SEO services |

    Your music is amazing. You have some very talented artists. I wish you the best of success.

  52. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.

  53. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.

  54. Your music is amazing. You have some very talented artists. I wish you the best of success.

  55. Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here.

  56. Your article is great and rewarding. I like it very much. Hope to read more posts from you.

  57. Please share more like that.

  58. This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it

  59. Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

  60. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.

  61. www.resul... | www.results.itschool.gov.in |

    Are you looking for Kerala SSLC result 2018? Want to download Kerala SSLC result 2018?

  62. This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff.

  63. That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally!

  64. Your music is amazing. You have some very talented artists. I wish you the best of success.

  65. Your music is amazing. You have some very talented artists. I wish you the best of success.

  66. I admit, I have not been on this web page in a long time... however it was another joy to see It is such an important topic and ignored by so many, even professionals. professionals. I thank you to help making people more aware of possible issues.

  67. Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have.

  68. You completed a few fine points there. I did a search on the subject and found nearly all persons will go along with with your blog.

  69. ramadan c... | ramadan calendar 2018 dubai |

    I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.

  70. walmart c... | walmart creditcard login |

    Walmart Credit Card and wallmart credit card login details in the check below

  71. Nice post mate, keep up the great work, just shared this with my friendz

  72. antimalwa... | antimalware service executable high cpu |

    Very Interesting and wonderfull information keep sharing

  73. appliance... | appliancetechnician.ca |

    I am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing.

  74. Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards,

  75. New web site is looking good. Thanks for the great effort.
    <a href="favbet-bonus.blogspot.com">favbet</a>

  76. New web site is looking good. Thanks for the great effort.

  77. Thank you very much for keep this information.

  78. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

  79. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!
    <a href="https:/...</a>

  80. This was a really great contest and hopefully I can attend the next one. It was alot of fun and I really enjoyed myself..

  81. Thanks for the blog post buddy! Keep them coming...

  82. testogen... | testogen before and afer |

    Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

  83. www.webroot.com/safe -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    https:/....org/safe/

  84. Where to seek out webroot Key Code? The Webroot security package is simple to setup &amp; install at webroot.com/safe. Simply find 20-character alpha-numeric code that is...
    http://...-safe.org/

  85. Web-root -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    https:/...-root.org/

  86. Experience next generation Security level with Webroot in your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere
    https:/...-com-safe/

  87. Xbox live codes.

  88. The Webroot security package is simple to setup & install at webroot.com/safe. Simply find 20-character alpha-numeric code that is written on the backside of the retail card. Here may be a sample Product Key to let you understand:
    xxxx-xxxx-xxxx-xxxx-xxxx

  89. Webroot Support experts can lend their hand to download, install and update Webroot Spy Sweeper Antivirus on your system. We can also repair all errors that may crop up while installing and configuring Webroot Antivirus on your PC. We can help you detect and remove malicious threats, malware and spyware by performing a quick scan on all files and folders. With our robust technology, we can destroy suspicious programs and infected files from your system. Our antivirus experts can clean all online threats, including Trojan, root kits, key loggers, and worms in just single sweep. We can optimize your computer’s speed and efficiency and also protect it from being sluggish.

  90. Experience next generation Security level with Webroot in your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.webroot.com/safe is a computer security software program for Microsoft Windows users that combine software as a service cloud protection with traditional Antivirus and anti-spyware desktop technologies. Built into the suite is a two-way firewall, a registry cleaner, Email anti-spam, secure browsing, anti-phishing and a password management service .The suite was initially released on July 26, 2010 as the 2011 version of the product.

  91. Gangstar Vegas is an open world action-adventure video game developed by Gameloft for Android, iOS.

  92. Thank you for sharing

  93. Visit www.norton.com/setup for setup, download, reinstall, enter and activate your norton product key to setup your account.Step-by-Step guide for Norton setup key, Download &amp; installation from norton.com/setup website.

  94. welcome to avg.com/retail website With the development of the digital world, online protection is crucial. It is extremely important to protect your PCs, Mac, computers as well as mobile devices and tablets with avg.com/retail. This can be done with the help of effective internet security and anti-virus products from avg.com/retail that safeguards all devices used on digital platforms.

  95. I got what you mean , thanks for posting .Woh I am happy to find this website through google.

  96. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.

  97. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

  98. Gamekiller apk is an android app to modify coins, gems, gold bars etc of any android games by using techniques of memory modifying. Game killer is not available on Google play store.

  99. I am glad you take pride in what you write. This makes you stand way out from many other writers that push poorly written content.

  100. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.

  101. Wow i can say that this is another great article as expected of this blog.Bookmarked this site..

  102. Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post.

  103. This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post.

  104. Impressive web site, Distinguished feedback that I can tackle. I am moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards.

  105. real esta... | real estate in Riviera Maya |

    i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future..

  106. Keep up the good work , I read few posts on this web site and I conceive that your blog is very interesting and has sets of fantastic information.

  107. Ergonomis... | Ergonomische Eingabegeräte |

    Nice post. I was checking constantly this blog and I’m impressed! Extremely useful info specially the last part I care for such information a lot. I was seeking this certain info for a long time. Thank you and good luck.

  108. корпорати... | корпоративные тренинги в Украине |

    I just found this blog and have high hopes for it to continue. Keep up the great work, its hard to find good ones. I have added to my favorites. Thank You.

  109. Love to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks.

  110. useful information on topics that plenty are interested on for this wonderful post.Admiring the time and effort you put into your b!..

  111. It's surprising you aren't more popular given that you definitely possess the gift.

  112. check it right now for sslc result

  113. Couldn't have enhanced myself. Wonderful and This blog is an untouchable work.

  114. The writer has made this blog in the most stunning way. Mind boggling!

  115. I found this is an informative and interesting post so i think so it is very useful and knowledgeable. I would like to thank you for the efforts you have made in writing this article.

  116. It is really nice article and I really read with interesting thank you for good information.

  117. Thank you for your sharing. Thanks to this article I can learn more things. Expand your knowledge and abilities. Actually the article is very practical. Thank you!

  118. The world of console video games changed forever when Sony and Microsoft started networks for online gaming on Playstation and Xbox platforms.

  119. En réalité cela se produit car l'on cherche à redimensionner un objet qui n'est pas encore présent sur la scène..

  120. Très bel article. Je dois dire que j'ai vraiment apprécié la navigation sur votre blog. Je vais m'abonner à votre flux RSS. Merci!

  121. Game Hacker is an android app which is very popular that is used to hack or manipulate many popular games.

  122. sf@gmail.com | brian holm lawyer san diego |

    An essential hotspot for the gathering of people that makes the peruser stride by step.

  123. Considering that we are Roblox gamers too, we were just fed up with the high prices for Robux which is the genealogy of this remarkable video game specifically if you have a free membership, it could be sluggish and pretty irritating to gather some Robuxs.

  124. Vulcan run time Libraries are the graphics standards same like OpenGL and DirectX

  125. The leading assignment help UK firm offers state of the art services to its clients with a promise of delivering all the required work well within the deadline.

  126. My friend recommended this blog and he was totally right keep up the fantastic work!

  127. I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you.

  128. When you trying to print any document through MS Office to connect a new printer or your printer drive is not working correctly
    https:/...available/

  129. Utilize the free cells in the upper left edge to keep cards you can not make use of during that time. The objective of FreeCell is to relocate all the cards to the 4 foundations heaps by constructing each suit up from Ace to King.

  130. Great post, I believe website owners should learn a lot from
    this blog its really user friendly. So much superb information on here :D.

  131. Cheap Ove... | Cheap Oversized Postcard |

    Not considering the image quality can give a poor look to the postcard <a href="https:/...;>Cheap Oversized Postcard</a>

  132. Check the expected price of OnePlus 5 in India. Get OnePlus 5 launch date, Specifications, Reviews, News and Images here. Check OnePlus 5 Specs And Reviews. Compare OnePlus 5 Prices From Various Stores.

  133. Bluestacks is a software that allows the users to download and install android apps on their Windows laptop or PC and that too free of any cost

  134. Welcome to vidmate app official website.easily download latest version of vidmate app from here.

  135. I think this is a really good article. You make this information interesting and engaging. You give readers a lot to think about and I appreciate that kind of writing

  136. This is an excellent post.Given so much information..This types of articles is very informative and i have bookmarked of your site because this content is very helpful.Wishing you the best of luck and i hope that next time i will see again this types of article..Thank you

  137. Stéphane... | Manipuler un élément chargé |

    Bonjour et merci pour la remarque ! Effectivement, je dois avouer ne pas y avoir pensé, mais vais certainement ajouter un cours à ce sujet.
    D'autant que depuis AS3, on peut totalement manipuler les attributs/méthodes des swf chargés ce qui n'était pas le cas avec AS2 (exception faite de gotoAndPlay, stop et quelques trucs sans grand intérêt).
    Je vais m'y employer :)

  138. Jean-Luc | gerer un swf chargé |

    Merci pour ton travail
    Il serait intéressant d'expliquer comment manipuler l'objet chargé aprés qu'on a fait l'addChild car lorsqu'il est sur la scéne, moi je n'arrive plus à le gérer
    Imaginons avoir chargé un swf... comment peut on utiliser les gotoAndPlay(n) ou stop() ou bien encore accéder aux variables contenues ds le SWF