Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

QuickColorCode.as

Name: QuickColorCode - easily add a color coded keyword to Flash authoring.
Author: senocular: www.senocular.com
Date: 1899-12-31T00:49:42.600
Documentation:
QuickColorCode: Add an actionscript keyword to be
color coded (blue by default) in your Actions panel in
the Flash authoring environment.  Since this coloring is
set when Flash is opened, you may need to restart Flash
for the coloring to take effect.

QuickColorCode("keyword" [, remove]);

Arguments:
- keyword: (string) the keyword to be added to (ore removed from) your custom coloring
scheme.
- remove: (boolean, optional) if true, the keyword passed is removed from custom coloring.
if null is passed as the keyword and remove is true, all custom coloring is removed.
Default: false 

Returns:
- a trace of the action resulting from the call.


QuickColorCode.kill();
- removes all of the installed color coding and deletes itself as an added bonus.
Arguments:
- none
Returns:
- a trace of the action resulting from the call.


Color coding is stored in an xml file in your Configuration\ActionsPanel\CustomActions
directory with the name QuickColorCodeActions.xml.  Removing this file is equivalent to
removing all of the color coding added with QuickColorCode (ie QuickColorCode.kill()).

Maybe not the most practical function ever, but it makes it quick and easy for people who
dont want to mess with custom actions XML at all. :)

Example:
// random examples of adding and removing
// words to be color coded:
QuickColorCode("MyObject", true); // try to remove "MyObject" from color coding
QuickColorCode("MyObject"); // try to add "MyObject" to color coding
QuickColorCode("myMethod"); // try to add "myMethod" to color coding
QuickColorCode("QuickColorCode"); // try to remove "QuickColorCode" from color coding
QuickColorCode(null); // try to add null to color coding
QuickColorCode(null, true); // try to clear all color coding (but "QuickColorCode" ;)
QuickColorCode.kill(); // try to clear all color coding added with QuickColorCode
trace(QuickColorCode); // QuickColorCode won't exist after a successful kill :)

// Output
Previous custom color coding not found; "MyObject" not removed.
No changes were made.

Success of adding "MyObject" to custom color coding: true
You may have to restart Flash for the changes to take effect.

Success of adding "myMethod" to custom color coding: true
You may have to restart Flash for the changes to take effect.

Don't remove "QuickColorCode" fool!
If you want to get rid of me, use QuickColorCode.kill();

Invalid string passed to QuickColorCode.
No changes were made.

Success of clearing custom color coding: true
Backup:

You may have to restart Flash for the changes to take effect.

Success of killing custom color coding: true

undefined

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
_global.QuickColorCode = function(word, remove){
	if (word == "QuickColorCode") return trace("Don't remove \"QuickColorCode\" fool!\nIf you want to get rid of me, use QuickColorCode.kill();\n");
	var endMsgT = "\nYou may have to restart Flash for the changes to take effect.\n";
	var endMsgF = "\nNo changes were made.\n";
	if (!word.substr){
		if (remove){
			var current = CustomActions.get("QuickColorCodeActions");
			var success = CustomActions.install("QuickColorCodeActions", "<customactions><colorsyntax><keyword text=\"QuickColorCode\"/></colorsyntax></customactions>");
			return trace("Success of clearing custom color coding: "+success+"\nBackup:\n"+current+endMsgT);
		}
		return trace("Invalid string passed to QuickColorCode."+endMsgF);
	}
	var actions = CustomActions.get("QuickColorCodeActions");
	if (actions == undefined){
		if (remove) return trace("Previous custom color coding not found; \""+word+"\" not removed."+endMsgF);
		else{
			var success = CustomActions.install("QuickColorCodeActions", "<customactions><colorsyntax><keyword text=\"QuickColorCode\"/><keyword text=\""+word+"\"/></colorsyntax></customactions>");
			return trace("Success of adding \""+word+"\" to custom color coding: "+success+endMsgT);
		};
	};
	var qcc_xml = new XML(actions);
	keywords = qcc_xml.firstChild.firstChild.childNodes;
	for (var i=0; i<keywords.length; i++){
		if (keywords[i].attributes.text == word){
			if (remove){
				keywords[i].removeNode();
				var success = CustomActions.install("QuickColorCodeActions", qcc_xml.toString())
				return trace("Success in removing \""+word+"\" from custom color coding: "+success+endMsgT);
			}else return trace(word+" already exists in custom color coding."+endMsgF);
		};
	};
	if (remove) return trace("\""+word+"\" not found in custom color coding."+endMsgF);
	var newWord = qcc_xml.createElement("keyword");
	newWord.attributes.text = word;
	qcc_xml.firstChild.firstChild.appendChild( newWord );
	var success = CustomActions.install("QuickColorCodeActions", qcc_xml.toString());
	return trace("Success of adding \""+word+"\" to custom color coding: "+success+endMsgT);
};
QuickColorCode.kill = function(){
	var success = CustomActions.uninstall("QuickColorCodeActions");
	if (success) delete _global.QuickColorCode;
	return trace("Success of killing custom color coding: "+success+"\n");
};