Having too much fun with this.
* Changes:
* 1.1 Started using actionsPanel.getText, setText. And setSelection for cursor position.
* 1.1.1 Fixed a typo in enterFrame
* 1.1.2 Not correctly finding end of file if no cursor specified. So specified cursor at end of each snippet. Added some snippets.
* 1.1.3 Added help function. Type &help and run command and it traces out a list of commands.
http://www.bit-101.com/extensions/ASExpander.jsfl
Background in case you’re seeing this for the first time:
http://www.bit-101.com/blog/?p=1620
http://www.bit-101.com/blog/?p=1627
Thanks! I’ll try it later …
You’re edits have made it look almost identical to mine 🙂 I was searching for ** instead of &cursor. I’m about to go home and will probably be playing around with this all evening!
Cool. I welcome any further suggestions.
I’ve made an “Add To ASExpander” script, which is working great except for the predictable problem of escaping newline and tab characters. The idea is that you select some text in the actions panel, then run the command. It prompts you for a key, and then adds it to the ASExpander.jsfl file. I am thinking along the lines of key.split(“\r”).join(“\\r”), but that’s not working. Here is the script, which is working fine if you manually enter \n and \t:
var ASExpanderFile = FLfile.read(fl.configURI + “Commands/ASExpander.jsfl”);
var selectedText = fl.actionsPanel.getSelectedText();
if(selectedText == “”){
alert(“Please select a snippet to add to ASExpander.”);
} else if(ASExpanderFile == “”) {
alert(“Unable to find ASExpander.jsfl in:\n\n” + fl.configURI);
} else {
var key = prompt(“Please enter a key for the selected snippet.”);
if(key != null) {
FLfile.write(fl.configURI + “Commands/ASExpander.jsfl”, ASExpanderFile.split(“map = new Object();”).join(“map = new Object();\nmap[\”” + key + “\”] = \”” + selectedText + “\”;”));
fl.actionsPanel.replaceSelectedText(“”);
}
}
PS – I guess it should be if(key != null && key != “”) instead of just if(key != null) – so that both entering an empty string (“”) and pressing cancel (null) are not accepted.
The Add to ASExpander is definitely a good idea. I miss something on the usage : your code goes in a .jsfl and acts as a command ? I did that and encoutered some errors. Could you tell me more ?
Yes, I have an ‘ASExpander – Add Snippet.jsfl’ file with that code it. What errors do you get? I’ve posted the file here just in case posting it to the blog has mucked up the code:
http://www.jamesthompsondigital.com/developers/bit-101/ASExpander – Add Snippet.jsfl
Okay. I have pieced together a more complete jsfl command. I can’t say that I have thoroughly tested it, but it is working so far for me. Here are its features:
* Select text in the actions panel and run command to add a map (you will be prompted for a key).
* Automatically escapes newline, tab and quote characters.
* Enter an already used key, and you will be asked if you would like to use the selection to replace the old map.
* Select the word “delete” and enter an already used key and you will be asked if you want to delete the key.
I don’t know if “Add Snippet” is still the best name now that it can add, edit and delete maps, but here it is:
http://www.jamesthompsondigital.com/developers/bit-101/ASExpander_-_Add_Snippet.jsfl
Just replace the underscores with spaces once it has downloaded and give it a better name if you can think of one 🙂
It works like a charm now !
Hi everyone,
For a while now my Flash CS3 has not been showing any additional jsfl scripts that I am adding to the Commands folder. Its really getting on my nerves. I’ve written some custom scripts too, and the only way I can run them is to open up the Commands folder and double-click the script file. Has anyone else had this issue where new commands don’t show up?
Yes I’ve restarted both Flash and my computer. Yes I know where the commands folder is. Is it possible that there are two commands folders, like one in Documents & Settings that I can’t find?
This is annoying!
Tim, yes, there are a few Commands folders. The one you are looking for is:
Mac: /[user]/Library/Application Support/Adobe/Flash CS3/en/Configuration/Commands
Windows: \Documents and Settings\username\Local Settings\Application Data\Adobe\Flash CS3\language\Configuration\
James, haven’t tested out your add snippet command. But it looks cool. Thanks for contributing.