Robots Rule | MindSculpt.net

New media has met its match.

The MindSculpt Design Syndicate focuses on code that works, from CSS, XHTML and JavaScript tips and tutorials to Flash and ActionScript how-to's. Robots not included.

AS2 Refresher: Loading External Bitmaps with loadClip()

Michael Becker

Michael has humbly acquired extensive design experience across multiple industry disciplines during his career in new media. In addition to his passion for web and Flash development, he has an uncanny penchant for zombies and robots. Let's be honest, who doesn't?

The following article assumes you have a solid understanding of Flash AS2 and the Flash interface, and skips all basic Flash setup instructions and explanations in effort to provide you with quick, concise information. It also assumes you have images ready to be loaded into your swf.

The AS2 refresher series aims to consolidate basic, everyday snippets for the most common tasks used by Flash developers working with legacy files. Basic explanations are included in the comments, since after all, who wants to read through a bunch of crap when you are just after the code? Enjoy.

AS2 sendAndLoad with LoadVars Snippet:

  1. // variables
  2. //——————————————————————————————————————————-
  3.  
  4. // create a var to hold the name of the bitmap we want to load
  5. var imageName:String = "image1.jpg";
  6.    
  7. // set a reference to the folder your images are in ›› the slash (images/) is added below when we assemble the path
  8. var imagePath:String = "images";
  9.  
  10. // set a new MovieClipLoader and immediately load the image into a movieclip on the stage named ‘container_mc’
  11. var mcLoader:MovieClipLoader = new MovieClipLoader();
  12.    mcLoader.addListener(this);
  13.    mcLoader.loadClip(imagePath + "/" + imageName, container_mc)
  14.  
  15. // functions
  16. //——————————————————————————————————————————-
  17.  
  18. // when the image has loaded, begin the ad unit animation
  19. function onLoadComplete(mc:MovieClip) {
  20.    
  21.    trace("image loaded from: " + imagePath + "/" + imageName);
  22.    trace("image loaded into: " + mc);
  23.    
  24.    // load has completed, call init() and start the app
  25.    init();
  26. }
  27.  
  28. // called while image is loading ›› insert preloading actions here
  29. function onLoadProgress():Void {
  30.    
  31.    trace("image loading…");
  32. }
  33.  
  34. function init():Void {
  35.    
  36.    // start your app
  37.    
  38.    // for additional progress event listeners associated with loading external bitmaps,
  39.    //    visit: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001381.html   
  40. }
Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

Category: Flash AS2 | Tags: , ,


Leave a Reply



Back to top