Compiling Flash Files from Flex
On May 20, 2008, Flash / Flex - 25 CommentsThis week, I had to do some flash work for TFE. As soon as a fired up flash and started programming I realized how lazy you get when programming in eclipse. I mean, auto import, code completion, all kinds of shortcuts… Compared to the flash IDE it’s heaven
. Now, I know that there are many IDE’s for flash Actionscript like SePY and FlashDevelop, but none of them really satisfies me like Eclipse does. The only problem with using Eclipse as Actionscript editor is the fact that you cannot build fla files in Flex Builder… or can you?I did some research in commandline compiling and stumbled upon (not using the SU toolbar tho
) a batch script which did almost exactly what I wanted: instruct the flash IDE to build a certain FLA file. I modified the script a bit so it won’t close flash and it runs testmovie instead of publish:
@echo off SET v_test=%1 SET v_result=%v_test:\=/% echo // > tempPublish.jsfl :start echo %v_result% echo filename = "file:///%v_result%"; >> tempPublish.jsfl echo fl.openDocument(filename); >> tempPublish.jsfl echo curr_doc = fl.getDocumentDOM(); >> tempPublish.jsfl echo curr_doc.testMovie(); >> tempPublish.jsfl shift if "%1" == "" goto end goto start :end start "C:/Program Files/Adobe/Adobe Flash CS3/Flash.exe" tempPublish.jsfl |
Save this file as flashpublish.bat or whatever suits you. Now we’ve got our batch file, it’s time to setup flex builder.
- Goto ‘Run’ -> ‘External Tools’ -> ‘External tools’
- From the configurations list, select ‘Program’
- Click ‘New’
- Give the configuration a name like ‘Flash Builder’ or something
- In the location box, locate the batch file
- Leave the Working Directory empty
- Enter the following string in the Arguments field:
${project_loc}/src/${project_name}.fla - Select the ‘Common’ tab and select ‘External Tools’ at the ‘Display in favorites menu’
- Hit apply and close.
You can now use Flex Builder for your actionscript projects. Just create a new Actionscript project (not a Flex project) and locate it in the same directory as the FLA file.
Make sure the projectname is the same as the filename of the FLA.
When you want to build, hit External Tools -> Flash Builder.
Now, to make it even faster to work with apply a shortcut to it:
- Goto Window -> Preferences
- From the ‘General’ section, select ‘Keys’
- Choose Modify and select ‘Run/Debug’ as category and ‘External Tools…’ as name
- At the key sequence name field, press the desired keyboard shortcut and klick Add
- Click OK, your shortcut is added and ready to be tested!
Now, you finally have a descent Actionscript Editor which is capable of building FLA files!
What others have to say:
I am trying you code and i am getting “the system cannot find the file tempPublish.jsfl i have looked every where for it and i cant find it…
I got Flex Builder with your tutorial to open the file “myTest.fla” and publish
. Then in flex i tried to draw a circle on the Document class slash Actionscript project “myTest.as” but the fla file don’t show any updates after publishing, there are no difference form the original one that i created manually…
reading “Now, you finally have a descent Actionscript Editor which is capable of building FLA files” i was under the impression that through the document class “myTest.as” in FLEX i was going to be able to update the FLA populate it with content… am I misunderstanding something ( i think i am… )
I am trying to create FLA and populate them dynamically with some simple shape boxes and text…. any feedback or links would be appreciated thanks, and great work by the way
Regards Brett
Fantastic! Finaly editing as3 in flex and being able to use fla as library! thanx!
@Brett: The myTest.as is generated by flex, Flash doesn’t do anything with it. You have to reference to it either by a movieclip (linkage) or set it explicitly as document class.
In addition, if you have a library of as3 files, you can access them in flex by setting a source path.
Can I use the flex sdk compiler and your script to compile a .fla ?
No, flash does the actual compiling. With this script you can use flex for your actionscript editing and send a command to flash to start compiling the fla. So you still need flash.
Excellent solution! I do all my as3 projects in flash with an fla, but author all as3 classes in flexbuilder 3. I’m getting quite sick of alt-tabbing to flash to publish. Now, the only problem is I’m on OS X. Any ideas on a similar solution?
Well, I’m sure there’s an OSX equivalent to batch scripting, but I’m not familiar with it and I’m sure you can run flash with optional arguments / jsfl files in OSX. So I think you have to dive in batch / commandline scripting for OSX. Since I don’t have an apple, I can’t help you there, sorry.
i’m about to start a big project at work and this tutorial got me setup exactly the way i wanted to. the silly thing is, i can’t figure out how to create a keyboard shortcut to my newly created command.
my version of Flex Builder is: 3.0.1.205647. has this “Modify” feature been removed in this version? i must be overlooking this..
Yeah, fb3 is a bit different.
Go to Preferences -> keys.
In the list, select External tools…
Set focus to the ‘binding’ field and press the desired keyboard shortcut.
Click apply, OK
Hope this helps.
i see. i had to check the “Include unbound commands” option for it to come up in that list. thanks for your time.
Hi lds, thanks for the great script. I am having a bit of trouble, however: when I run the script, it opens Flash CS3 up, but does nothing. When I look at the newly-opened Flash window, it is asking for me to either open a file or create a new one (you know, that welcome Flash screen…). Am I doing something wrong?
Thanks!
Hmm, does it give an error in the output window of flash? A possibility is that flash can’t find your .fla, which means the specified path is incorrect.
I´ve got the same prob like Brett “system cannot find the file tempPublish.jsf”… If Somebody knows the beginning of this problem plz give me a feedback!
I dispair…..
Where is you batch file located? I believe it creates the jsfl file in that same directory. Make sure you have write access to that dir.
You could also try to create the jsfl file yourself, next to the batch file. (Just create an empty one). That way you’re sure it exists. It could be that the batch file can’t create the file, but can write to it.
Hope this helps!
I found the error of ‘system cannot find the file tempPublish.jsf’
In the batch file, replace the
>signs with >Just so I get this correctly, I still need CS3 on my machine. I can’t just work with .fla within Flex. Or can I?
Also, what is the right way to convert an existing Flash project(.flas, .psds) to Flex?
Thanks.
Yes, you need Flash CS* to compile…
and no, there is no easy way to convert .fla files to a flex project.
Thanks for the quick response. I know that there is no easy way. But is there a way at all to convert? Or the only option is to rewrite from scratch.
I don’t think so, since flex doesn’t have a timeline, doesn’t work with movieclips (it works with displayobjects), etc.etc.
You COULD mark your movieclips to ‘Export for actionscript’ and then import them into your flexapplication (With the embed tag).
[...] met dank aan dit artikel [...]
“the system cannot find the file tempPublish.jsfl” – same here!! what do I have to do ?
Make sure the batch and the jsfl file are in the same directory. You could try to create an empty jsfl file, so the system can find it.
take look at this solution, that avoids need for compiling any as3 code from flash ide:
http://www.actionscript.org/forums/showthread.php3?p=927260#post927260
That’s another way of doing it, but it’s a lot more code. Also, I’ve experienced some bugs when using Flash CS4 and the suggested approach. (Movieclips which won’t convert to sprite and vice-versa)
Leave a Reply