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.

Tag: ActionScript


AS2 Refresher: Loading External Bitmaps with loadClip()

February 15th, 2010 — 9:05am

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. }

Comment » | Flash AS2

AS2 Refresher: sendAndLoad with LoadVars

January 22nd, 2010 — 2:19pm

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 are dealing with a server-side script that is set up to receive parameters and send back a response.

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. // set a ref to hold your URL
  5. var myURL:String = "test.html";
  6.  
  7. // set a new LoadVars object
  8. var result_lv:LoadVars = new LoadVars();
  9.  
  10. // function that fires when a result is received from the server
  11. result_lv.onLoad = function(success:Boolean) {
  12.    
  13.    if (success) {
  14.       
  15.       trace ("——————————————————-")
  16.       trace (">>>>> SUCCESS!");
  17.       trace ("——————————————————-")
  18.       
  19.    } else {
  20.       
  21.       trace ("——————————————————-")
  22.       trace (">>>>> ERROR!");
  23.       trace ("——————————————————-")
  24.    }
  25. };
  26.  
  27. // instantiate a new LoadVars object
  28. var myLoadVars:LoadVars = new LoadVars();
  29.    
  30.    // assign parameters to the object
  31.    myLoadVars.var1 = "Robots";
  32.    myLoadVars.var2 = "Aliens";
  33.    
  34.    // send our variables to the value in myURL and await the response which will be caught by ‘result_lv.onLoad’
  35.    myLoadVars.sendAndLoad(myURL, result_lv, "POST");
  36.  
  37. // make sure your URL is configured correctly by tracing out the compiled syntax
  38. trace("posting to: " + myURL + "?var1=" + myLoadVars.var1 + "&var2=" + myLoadVars.var2);

Comment » | Flash AS2

AS2 Refresher: sendAndLoad XML

January 12th, 2010 — 11:23am

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 are dealing with a server-side script that is set up to receive parameters and send back XML.

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 XML Snippet:

  1. // variables
  2. //——————————————————————————–
  3.  
  4. // set a ref to hold your URL
  5. var myURL:String = "test.html";
  6.  
  7. // set a new XML object
  8. var myXML:XML = new XML();
  9.    myXML.ignoreWhite = true;     
  10.    myXML.onLoad = onMyXMLLoad;   
  11.  
  12. // functions
  13. //——————————————————————————–
  14.  
  15. // runs when the xml is successfully loaded from the url
  16. function onMyXMLLoad(success:Boolean) {
  17.    
  18.    if (success) {
  19.       
  20.       trace("XML LOADED FROM SERVER");
  21.       
  22.       // xml has been loaded, call init()
  23.       init();
  24.       
  25.    } else {
  26.       
  27.       trace("ERROR: XML NOT LOADED FROM SERVER");        
  28.    }
  29. }
  30.  
  31. // function that runs after the XML has been returned and loaded from the server
  32. function init():Void {
  33.    
  34.    trace("init() called");
  35.    trace("");
  36.    
  37.    trace("myXML: \n" + myXML);
  38. }
  39.  
  40. // load vars
  41. //——————————————————————————–
  42.  
  43. // set a new LoadVars object
  44. var myLoadVars:LoadVars = new LoadVars();
  45.  
  46.    // assign parameters to the object
  47.    myLoadVars.var1 = "Michael";
  48.    myLoadVars.var2 = "Becker";
  49.  
  50. // send our variables to the value in myURL and await the response which will be stored in myXML
  51. myLoadVars.sendAndLoad(myURL, myXML, "POST");
  52.  
  53. // make sure your URL is configured correctly by tracing out the compiled syntax
  54. trace("posting to: "+ myURL + "?var1=" + myLoadVars.var1 + "&var2=" + myLoadVars.var2);

Comment » | Flash AS2, XML

Back to top