| |
|
|
|
|
|
|
|
Organizing and structuring your Flash projects (part 4)
Organizing your code
Centralize your code
If you have ever had to edit a Flash file that was created by somebody else you might have realised that sometimes it can turn into a real nightmare. Because actionscript can be attached to movie clips
it can get really tricky to locate every bit of code. Therefore it is strongly advised that you should keep your code on the top layer in the first frame as far as it is possible depending on your project.
For example, Instead of attaching the following code to a Movie clip called myButton :
onClipEvent(load){
this.onPress = function(){
}
} |
it is best to put the following code on the first frame of the top layer.
myButton.onPress = function(){
}
|
It's best to go for the second option because if someone else edits your file he won't have to look for every Movie clip and select them to see if there is code attached to them.
Keeping your code external can be a good option
Sometimes you need to reuse some bits of code across different projects, in that case it could be a good choice to keep your code in external .as files and to include it in your actionscrit using the #include directive, for example :
Do not place a semicolon (;) at the end of the line that contains the #include directive or you will end up with a " Malformed #include directive" error.
Keeping the code external as much as possible will make it more readable and it is easier to update a little module than to scroll through 2000 lines of code.
Comment your code
It is a good practise to comment your code, not just for others but even for you. It will make it a lot easier to spot the different modules and functions and the interaction between them.
If, despite the above advice, you end up with a messy Flash file all is not lost. You can use the Movie explorer (fig11) to explore the file and search for buried actionscript, text, movie clips, sounds etc...
fig11
Select the type of assets you want to display in the Show menu then type what you are looking for in the Find box. You might sometimes discover some hidden treasures, who knows :)
Hopefully this article will help you to get a bit more organized or comfort you that you are on the right path :)
|
|
|
If you think this page is providing useful information, don't hesitate to leave a comment.
|
|
|
|
|
|
|
|
|
Copyright ©2006-2008 flashvalley.com - All rights reserved |
|