I have been blogging for about a year now. Its an addictive habit and to be very honest with you not an easy task to keep up with your blog and the trends of other blogs. I have also been on a constant journey developing my Actionscript skills and just recently migrating from AS2 to AS3. Along the way i have viewed many peoples code and of course tried to write clean code myself. It can be a daunting task especially when you start authoring/writing 100’s of lines of code.
Here is a list of Mistakes i feel that beginner to advanced coders make. The spectrum is broad and even those who have been coding Actionscript in the Flash IDE for some time now will make these mistakes. It’s not that advanced users of Actionscript dont know correct syntax its just a matter of time and eventually laziness on the developers part.
- NOT USING CAMEL CASE AND SUFFIXES:
Once you have dragged a symbol onto the stage the property inspector gives you a neat little way to designate that instance with its own unique name. Flash devlopers who instantiate the symbol through Actionscript should always follow this method to refer to that instance of a symbol, movieclip or button.
As you can see in the below screeenshot myClip_mc is the correct naming convention to use as the symbols instance. myClip is how you would use the correct camelCase structure and _mc would be the correct suffix to use so thatwhen you see it in code you know exactly immediately that its referring to a movie clip.
myClip_mc.stop(); – The actionscript code and correct naming conventions that help you easily recognize and seperate different symbols in your code.
- STRICT DATA TYPING:
Strict data typing also allows for Flash to associate a variable with an object to help you with code hints when using that object. Before, this was only possible using underscore suffixes in your variable naming. Now you have the option of using strictly typed variables instead, allowing for more room in your own naming conventions. (Note: XML definitions will still be needed for code hints to function properly.)Typing is always placed following a variable or function declaration. For variables, the type is placed immediately after the variable name separated by a colon (:). For functions, placement directly after the parameters list, also separated by a colon. Function types here, however, refer to the type of the value that the function is returning. If the function has no return, Void is used. Also, for functions, the parameters used can too be strictly typed.var variableName:Type = value;
function functionName(parameter:Type):returnType {} - ERRORS IN THE FUNCTION CHAIN:
When creating complex movies, you will have several functions that act as event handlers for various objects, as well as generic user-defined functions. Some functionality may not work at all when you test your movie. Before checking for any other error, please, check if the relevant function is actually called. Just place a trace(’in’); action at the beginning of the function to see if it is called. If you don’t see ‘in’ in the output panel when you test your movie the function is never called. Most likely this is simply a targeting error; double-check your object and function names to see if they are coherent. - FILES DON’T WORK ON THE SERVER:
Please, before anything else, when files don’t work online, first check if all the support files are correctly uploaded. I once had a problem on a server when i didn’t change the persmissions of the xml files to read the swf.Place your HTML file and your SWF in the SAME folder, OR use absolute URLS. Of course, update the HTML file to match the situation. When Flash encounters a load command that uses a relative URL it passes it along to the browser. The browser must decide whether that URL is relative to the Flash file or to the HTML file. If they are in the same folder, there is no ambiguity. However, if that is not the case, do you know what it will choose? I don’t either! Save yourself the trouble, keep the main swf in the same folder as the HTML.When files are loaded through one of Flash’s numerous load functions (loadMovie, MovieClipLoader.loadClip, XML.load, Sound.loadSound, etc.), there is always a lag between the load call and the data being received. You must take that into account. Never play with a movie you’re not 100% sure is loaded. Using MovieClipLoader and LoadVars is safer than loadMovie and loadVariables because of all the neat loading events they fire.Double-check if your preloaders are working. If you don’t have them, use them! Check out the progress bar component, it can hook to most loading functions and objects, so you’ll have visual feedback.
