In the comments of my last post, James Thompson kindly pointed out that fl.actionsPanel has getText() and setText() methods, not to mention setSelection(). Thanks James! With this, I was able to get cursor positioning in there. Just put “&cursor” anywhere in the snippet, and with any luck, that’s where the cursor will go after the text replacement is done.
Got pretty messy doing that. The string in JSFL and the string in the editor return different values for getIndexOf() – seems to vary on newline characters. So I had to assign the text with the cursor info, get the index, replace the cursor info with nothing, and reassign the text. Also it wouldn’t find the &cursor string if it was followed by a newline either, so I’m just searching for &curso, which is pretty hacky but works.
Also slapped an MIT license in there and made it available for download.
http://www.bit-101.com/extensions/ASExpander.jsfl
Again, put it in your commands folder in Flash CS3 / CS4:
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\
And assign a shortcut key to that command.
Also, check it out, we have video of it already!
http://www.video-flash.de/index/asexpander-code-snippets-in-flash/
oops, little typo in the enterframe handler. fixed. v 1.1.1 is the one up there now.
I had some problems with cursor position on Mac. So I figured out this:
invisibles = script.split(“\n”).length + script.split(“\r”).length;
fl.actionsPanel.setText(script);
index = fl.actionsPanel.getText().indexOf(“&curso”) + invisibles;
Seems to work?!
Blah, it doesn’t work if you are adding snippets in the middle of the script. So you can remove previous comment, sorry. But there are some problems with new line & return characters..
Hello,
I’ve question about the documentation of JSFL, where do you find it ?
I never find anything really complete, juste only some demostration or a begin of explanation.
And without documentation, it’s difficult to know what is the limits of this language.
Thank’s a lot.
Dear Keith,
I want to do a PhD on ActionScript 3.0. I am reading your book on Animation. My idea is “What model does Flash give you leading to ….”I am not sure that is sufficient for a PhD. Have you any ideas?
Regards
Hugh
Ville, I’m on a Mac too and it’s working fine for me. Although, like I said, it was pretty tough, so I’m not surprised there’s still some glitches in it. Does it not work correctly with the snippets I provided?
Armetiz, I wrote the book Extending Flash MX 2004 with Todd Yard. It’s still the only complete book on the subject. It’s missing some of the newer stuff, but overall holds up pretty well for a 4 year old tech book.
Hugh. I’m not sure what you are asking.
Thk you so much 🙂
That is definitely a very non intrusive solution to make flash ide a better coding machine 🙂
Hi keith, I’m still trying how to use this ASExpander, I can’t get it work, maybe you can give me a guide how to assign a shortcut key, since I’am new at user script (.jsfl)
.
.
thanks ^^
Ahhh, finally I’ve figured out how to use this ASExpander, once again, thanks for this useful script ^_^
.
.
Can anyone provide a quick post/guide on how to create a shortcut key for this command?
Thanks.
Pretty good and surprisingly simple!, thanks Keith.
Hi iv tried this and get
The following JavaScript error(s) occurred:
At line 56 of file “ASExpander.jsfl”:
TypeError: script has no properties
any help on this, i didnt even know flash had this… 🙂
I get the exact same error, but on line 57. Any help would be great. 🙂
Not sure what’s going on there. Seems to be failing on this line:
if(script.indexOf(“&help”) != -1)
Which probably means that this line did not work:
script = fl.actionsPanel.getText();
What version of Flash are you using this on?
Hi kp,
I tried this on CS3 and CS4 now, i still get the same error.
Hi Keith, I saw you yesterday on FITC Amsterdam and I’m very interested in ASExpander. I just wanted to ask you if you plan on making it Flex-capable, like with a Flex Builder/Eclipse plugin?
I realized that asexpander works fine in a .fla but not when editing a .as.
Is there a way to use commands in a .as ?
Thx
I don’t think there is a way to access .as docs through JSFL. At least there wasn’t originally. Haven’t really kept up with the updates.