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.

Category: 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);
Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

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);
Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

Comment » | Flash AS2, XML

The lost arts of Flash part 1: Commenting

November 12th, 2009 — 11:13am

Becoming proficient in programming ActionScript in Flash takes more than spewing object-oriented buzzwords and writing complex classes only decipherable to elite Flash geeks. In my opinion, there are three lost arts in Flash programming; in this article we’ll talk briefly about commenting.

How could such fundamental techniques as these actually be on the verge of extinction, you ask? The answer is obvious: Amidst the daily whirlwind of demanding clients and looming project deadlines, it’s easier (and faster) to code projects without taking the time to include explanations for each line of code you type.

The reality however, is this: The time you take up front to properly comment your code and add meaningful trace statements within your ActionScript, the more time that will be saved when you revisit this file in 2 weeks, 2 months or 2 years. It also serves as the key to other developers who may need to jump in on your project or make updates in your absence. If you’re already commenting your code, I applaud you and grant you the permission to skip the rest of this article and spread the gospel.

Commenting Your Code
Commenting your ActionScript should be second-nature. It’s probably the easiest element you can contribute to your Flash application. There are countless techniques and preferences on how commenting should be formatted. The most important aspect of commenting is that you are clear and concise, so that your functionality will make sense to someone else (and even yourself) later down the road. Comment every variable, function and loop in your application so it reads fluently as a step-by-step guide to how your brain works. Also make sure you use variable and function names that make sense (one of the ‘lost arts’ to be covered in a subsequent article).

While programming your app, it’s helpful to keep the following in mind:

  • Will someone else be able to understand how I programmed this app?
  • In 2 weeks (months, years), will I be able to understand how I programmed this app?

Wow, that’s a short list. That’s because commenting should be an integral part of your workflow. Taking the extra time to type a few comments will save you (or someone else) their time and their sanity, and make you look like a well-balanced, ‘big picture’ oriented Flash programmer.

Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

Comment » | Flash AS2, Flash AS3

Back to top