Tricks of the Trade

Very good to know =)

Simple and practical, that’s brilliant! :slight_smile:

a little editing trick in
[size=3]Commenting[/size]

  • when commenting large blocks of code you may want to easily comment or uncomment any one block without too much effort.

The most painful way is using // It comments out one line so allows you to be selective, but in terms of larger blocks you’re out of a lot of typing.

In favor of that is /* */ for commenting a lot of lines at once. These are much faster but can still be a little cumbersome since they have both a beginning and and an end. So in turning these on and off you would have to add/delete these at bot the front and the end of the code block deleted.

The trick here is using both // and /* / together. In doing this, you can create a / */ block that is easily commented or uncommented by typing/deleting one character. JOY =) Example:


/*
trace("this");
trace("is");
trace("commented");
//*/

//*
trace("this");
trace("is NOT");
trace("commented");
//*/

(note the forum formatting wont show the second part uncommented though it really is in Flash)

The only change is the / infront of the first /* This makes the /* a commented * with // The ending //*/ is a commented ending / but if the / is in effect, the // commenting on that line wont ‘count’ and that */ will properly terminate the comment block

Its a little thing but it can be useful when testing and debugging when you find yourself doing this a lot with different sections of code.

[size=3]Code Base[/size]
Keeping foundation code out of the way

  • When dealing with rather large projects (or even smaller ones for that matter), you may be providing for your project a set of base classes or prototypes from which a lot of your structure will be based on or will take advantage of. If not linked in an external file and added with a #include, then usually this code is just pasted somewhere in the first frame of your movie. This, however, can at times be a bit cumbersome having large blocks of code sitting there in your main timeline taking up space and just getting in the way. This doesnt have to be the case though.

To get that junk out of your way completely, giving yourself a completely fresh (but enhanced) Flash pallete to work from, you can decide to place your code in a movieclip. This movieclip will then act as a container for your code; a place for it to be stored yet still be available for use on the main timeline or where ever you decide you may want to use it.

What to do:
[list]
[]make a movieClip:
[
]be sure to export for actionscript and do so in the first frame. The linkername is irrelavent - just be sure not to give it a name that might be used by something else.
[]in that movieclip place your code any way you want, in whatever layers you want (to help with organization and seperation of classes or whathaveyou)
[
]before all the script in that movieclip put a [color=blue]#initclip[/color] and after all the script put a [color=blue]#endinitclip[/color]
[/list]
Thats it. The movieclip does not have to be on the stage; It can operate just fine out of the library and not incovenience you any other respect. Now you have a completely clean flash movie to work from (aside from that clip in the library) with enhanced features all outlined in you classes/prototypes youve put in your code base … container … movieclip … thing. :slight_smile:

that’s awesome Sen, very useful =)