Monday, July 31, 2006

Mac FlexWeaver: Edit & Compile Flex Apps in Dreamweaver

Last Monday, I wrote about how you can configure Dreamweaver to edit and compile MXML. However, that method only works in Windows, since it uses some Windows-only (and undocumented) methods of the Dreamweaver Extensibility API.

It is a week later, and I have been busy brewing up a solution for us Mac users. One caveat at the outset: I'm on an Intel-based Mac, and so I haven't tested any of this on the Power PC architecture. This procedure requires Dreamweaver 8, and assumes that you have installed the Flex 2 SDK.

For your convenience, I have packaged the necessary files into a handy zip archive. You can download them here: http://labs.tom-lee.com/FlexWeaver/FlexWeaver.zip.

Installation

Opening the package, you'll see several folders. This section will tell you what they are, and where to put them.

  1. Commands - Contains the necessary files for two new Dreamweaver command extensions. Place the contents of this folder in Dreamweaver's "Commands" directory. (Dreamweaver 8:Configuration:Commands)

  2. DocumentTypes - This contains a copy of the file MMDocumentTypes.xml, which has been modified to allow Dreamweaver to treat MXML files like XML files instead of plain text. Place this in Dreamweaver 8:Configuration:DocumentTypes. Note: if you have already modified your MMDocumentTypes file for another purpose, don't overwrite it - instead, manually edit line 150 like so: <documenttype id="XML" writebyteordermark="false" file="Default.xml" macfileextension="xml,xsd,rss,rdf,dtd,vtm,vtml,csn,config,mxi,mxml" winfileextension="xml,xsd,rss,rdf,dtd,vtm,vtml,csn,config,mxi,mxml" internaltype="XML">

  3. Helper - Contains an AppleScript application called FlexCompileHelper.app. This bridges the gap between Dreamweaver and the Flex compiler, as I'll explain later. You can put this file anywhere you like.

  4. mxmlc - Contains a copy of the mxmlc shell script from the Flex 2 SDK which has been modified to allow support for spaces in filenames. Place this in flex_sdk_2:bin. Feel free to name this file something else if you don't wish to overwrite the one in the SDK.


Configuration

After you have copied the files to their proper locations, launch Dreamweaver. In the "Commands" menu, you should now see two new commands: Flex Compile, and Flex Preferences. Flex Preferences allows you to specify the location of the Flex compiler, the FlexCompileHelper app, and the output path for your SWF file, as well as any command line options you wish to use.

As you can (hopefully) see from the screen-shot, I have left the SWF Output Directory field blank. Since it is blank, SWFs will be placed in the same directory as their corresponding MXML files. Also, I have typed "-incremental=true" in the Additional Compiler Options field, to enable incremental compiling. When you click the "Save" button, a file called "FlexCompilerPreferences.txt" is created in your Dreamweaver configuration folder. This file merely stores all the values you enter into the Flex Compiler Preferences dialog.

Before we continue on, it would be a good idea to set MXML files to open in Dreamweaver. To do so, select an mxml file (you can find one in flex_sdk_2:samples) and go to File > Get Info in the Finder. Find where it says "Open With", select "Other" from the drop-down menu, and then browse to your Dreamweaver installation. Once you have Dreamweaver selected, you can click the "Change All" button to make all MXML files open in Dreamweaver.

Now it's time to compile something. Just open an MXML file in Dreamweaver, and select Commands > Flex Compile. This does a number of things:


  1. The Flex Compile command reads the Flex Compiler Preferences and creates a file on your hard drive called "FlexCompileJob.txt" in the same directory as the Flex Compile Helper application. This file contains 4 items: the path to the mxmlc shell script in the Flex 2 SDK, the path to the MXML file being compiled, the output path for the SWF, and any additional command-line options. Then, it launches the Flex Compile Helper application.

  2. The Flex Compile Helper application reads FlexCompileJob.txt, creates a command-line for the job, and passes it to the mxmlc shell script.

  3. When the mxmlc script returns its output, the Flex Compile Helper writes that output to a text file (FlexCompileOutput.txt) and instructs Dreamweaver to open that file.

  4. Flex Compile Helper instructs the Standalone Flash Player (located in the Flex 2 SDK) to open the SWF, and makes that window topmost.

This gives us the basic functionality to edit and preview a Flex 2 application from within Dreamweaver.

Error Checking

If the Flex Compile Preferences have not been set correctly, or an MXML file is not the active file in Dreamweaver, the Flex Compile command will not be available. Here is a list of the conditions under which Flex Compile will be grayed out:

  1. FlexCompilerPreferences.txt does not exist or is empty

  2. No compiler is specified, or the specified compiler does not exist

  3. No Flex Compile Helper app is specified, or the specified one does not exist

  4. No document is open

  5. The active document is not an MXML document


Further Explanation

This may seem like a lot of moving parts to achieve what should be a simple task. It was easier on Windows, thanks to the MM.createProcess command, which allowed me to call mxmlc directly from Dreamweaver and also catch its output. Unfortunately, this command does not work on the Mac. So, I had to create the AppleScript application which I could call with the more standard dreamweaver.openWithApp command. Since that command does not facilitate passing data to the application it's launching, I had to first write the necessary parameters into a text file which the application could then read.

I also spent a fair amount of time fighting with the mxmlc shell script, which choked on spaces in filenames. By default, it treats a space as an argument separator. If you open mxmlc in a text editor, and look at the last line, you will see this:
java $VMARGS -jar $FLEX_HOME/lib/mxmlc.jar $*
To fix it, I changed it to this:
java $VMARGS -jar $FLEX_HOME/lib/mxmlc.jar "$@"
For the exact reasons why, check out this page on bash scripting. I don't want to get into it right now, it kind of gives me a headache. With that line of code in there, you can escape any spaces in your filename by surrounding the filename in single quotes. FlexCompileHelper takes care of that for you, but if you put any file paths in the Additional Compiler Options field, you'll need to take that into account.

By the way, if you want to see what's in FlexCompileHelper.app, feel free to open it up. I have not protected the contents from being decompiled, so you should be able to see it in Script Editor.

Conclusion

Well, that's it for now. Can this be improved upon? You betcha. This meets my needs for now though, so I probably won't spend too much more time on it. If you have a suggestion on how to streamline this puppy, I'm all ears. I'm kind of intrigued by the fact that even Dreamweaver's code hinting is extensible. I may take on the challenge of adding code hinting to FlexWeaver, but if I do, it won't be for a while. Enjoy, and let me know if you have questions or comments.

Was this post helpful to you? If so, please consider making a small donation to keep this blog going.

17 Comments:

Blogger Rick Z said...

This post has been removed by a blog administrator.

10:51 AM  
Blogger Rick Z said...

Hey Tom,

I followed your directions to the letter and when I selected the "Flex Compile" menu command I received the following error message from the FlexCompileHelper:

"Can't get item 4 of {/Applications/flex_sdk_2/bin/mxmlc", "/Applications/flex_sdk_2/samples/explorer/explorer.mxml", "/Applications/flex_sdk_2/samples/explorer/explorer.swf"}.

Any ideas as to what would cause this and how I might fix it?

11:56 AM  
Blogger tom said...

Hey Rick, sorry you're having trouble with it. I should be able to take a look at things this evening. Meanwhile, what version of OSX are you running? Are you on a Power PC or Intel-based Mac? Are you using any additional command-line arguments (in the "Additional Compiler Options" field)? If not, try '-incremental=true' and let me know if it works that way. This is probably an issue in my AppleScript. If so, I'll fix it as soon as I can.

7:33 AM  
Blogger Rick Z said...

I'm running on an Intel based mac with 10.4.7 installed. Adding the '-incremental=true' got it to compile the swf's. Thanks Tom!

6:33 PM  
Anonymous Phil M said...

How can I add an "mxml" document type in the DW preferences so I can color code my code? I assume I would just add something to a JS file somewhere in the Dreamweaver install (?).

6:32 PM  
Anonymous Andrew Muller said...

Many thanks Tom, I used your plugin to build about 80% of this app: Flex Video Show & Snap app.

10:36 PM  
Anonymous sandeep said...

hello

my name is sandeep, i have one JSP page can i implement it in FLEX 2.0 , as i am very much interested to design the UI part in FLEX 2.0 , can i make it, the JSP page is a login page it contains username and password textfields and onclicking the submit button it has to validate the user and password is valid or not, and onclicking reset button it has to clear the textfields. can u give suggest how to implement this in FLEX 2.0 ,

thanks & regards
sandeep.mk@adobe.com

4:15 AM  
Blogger tom said...

Sandeep,

From what you describe, the UI should be a trivial task in Flex. Here are some quick start guides to get you started:

http://www.adobe.com/devnet/flex/?tab:quickstart=1

Good luck!

6:50 AM  
Blogger Andrew said...

Sorry, posted this on the Windows version.
Thanks for putting this together its a great! I have a problem though:
I tried using the MMDocumentTypes.xml but DeamWeaver pops up with a dialog saying the doc types "...will not be added because it uses a file extension that is already associated with a prior Document Type" (this is with alll of the doc types in this file I think). I even tried manually editing the file but its the same. It seems that even if you don't change anything within this file (Save as) it throws up the pop-ups.

3:36 AM  
Blogger arieljake said...

Any progress on code hints for Flex in Dreamweaver?

12:00 AM  
Blogger tom said...

Sorry, no - I started using Flex Builder instead. It seemed like a better use of my time. :)

8:25 AM  
Blogger Internet-Marketing said...

Hello,

This is a very good article.


Suchmaschineneintrag
Besuchertausch
Newsletterwerbung an über 82.000 User
Versicherungsvergleich
Handyshop
Handy-Angebote

5:54 AM  
Blogger Internet-Marketing said...

Hello,

This is a very good article.

Search Engine Optimization
Artikel News

11:38 AM  
Anonymous Anonymous said...

Hi Tom,

Have been working out for ages how to do this stuff without using FlexBuilder on my G5 Mac and all I can say is a HUGE thanks as it appears to work fine for me :)

Definitely going to be using Flex more now!

Mike London

10:53 PM  
Anonymous tires said...

companies marketing mineral makeups and also get the best bargains in mineral makeup you can imagine,
find aout how to consolidate your students loans or just how to lower your actual rates.,
looking for breast enlargements? in Rochester,
homeopathy for eczema learn about it.,
Allergies, information about lipitor,
save big with great bargains in mineral makeup,

change edition interviewing motivational people preparing second
,

interviewing motivational people preparing second time
,

interviewing people motivational preparing for a second time
,

black mold exposure
,

black mold exposure symptoms
,

black mold symptoms of exposure
,

free job interview questions
,

free job interview answers
,

interview answers to get a job
,

lookfor hair styles for fine thin hair
,

search hair styles for fine thin hair
,

hair styles for fine thin hair
,

beach resort in the philippines
,

great beach resort in the philippines
,

luxury beach resort in the philippines
,
iron garden gates, here,
iron garden gates,
wrought iron garden gates
, here
,
wrought iron garden gates
,
You: The Owner's Manual: An Insider's Guide to the Body That Will Make You Healthier and Younger
,
eat eating mindless more than think we we why
,


texturizer,
texturizers here,
black hair texturizer,
find aout how care curly hair,
find about how to care curly hair,
care curly hair,
lipitor rash,
lipitor reactions,
new house ventura california,
the house new houston tx,
new house washington dc,
new house pa philadelphia,
san antonio tx house new,
house new pa philadelphia,
new house washington dc,
new house ventura california,
the house new houston tx,
house new san antonio tx,
the house new houston tx, that you are looking for,
new house ventura california, you need to buy,
new house washington dc,
house new pa philadelphia,
new house san antonio tx,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

chocolate esophagus heartburn study
,

chocolate esophagus heartburn study
be informed,

digestion healing healthy heartburn natural preventing way
,

digestion healing healthy heartburn natural preventing way
,
sew skirts, 16simple styles you can make!,
sew what skirts 16 simple styles you,
rebates and discounts on sunsetter awnings,
sunsetter awnings discounts and rebates,
discount on sunsetter awnings


truck and bus tires 12r 22.5, get the best price,
tires truck and bus 12r 22.5 best price,
tires truck bus tires12r 22.5 best price,
plush car seat strap covers,
car seat strap covers,plush,
car seat strap, plush covers,
oscoda voip phone systems, the best!,
oscoda voip the phone system,
oscoda voip phone systems,
exterior iron gates,
oriental wrought iron gates,
powder coated iron garden fencing,

2:58 AM  
Anonymous air bed said...

black mold exposure,
black mold symptoms of exposure,

wrought iron garden gates,
your next iron garden gates, here,

hair styles for fine thin hair,
search hair styles for fine thin hair,

night vision binoculars,
buy, night vision binoculars,

lipitor reactions,
lipitor reactions,

luxury beach resort in the philippines,
beach resort in the philippines,

homeopathy for baby eczema.,
homeopathy for baby eczema.,

save big with great mineral makeup bargains,
companies marketing mineral makeups,

prodam iphone praha,
Apple prodam iphone praha,

iphone clone cect manual,
manual for iphone clone cect,

fero 52 binoculars night vision,
fero 52 night vision,

best night vision binoculars,
buy, best night vision binoculars,

computer programs to make photo albums,
computer programs, make photo albums,


craftmatic adjustable air bed
craftmatic adjustable air bed, info here

boyd night air bed
boyd night air bed, low price

air bed in wisconsin
best air beds in wisconsin

cloud air inflatable bed
best cloud air inflatable beds

portable sealy air bed
portables, sealy air beds

aluminum rv luggage racks
aluminum made, rv luggage racks

air bed form raised
best air beds form raised

support equipments aircraft
best support equipments for aircrafts

informercials bed air
best, informercials bed air

mattress sized air beds
best mattress sized air bed

antique doorknob identification
antique doorknob, identification tips

troubleshooting dvd player
troubleshooting with the dvd player

flat panel television lcd versus plasma
flat panel television, lcd versus plasma pic the best

causes of economic recession
what are the causes of economic recession

free printable tax forms
free printable IRS tax forms

bed air foam adjustable
bed air adjustable foam

hoof prints antique and unusual equestrian prints
hoof prints, antique equestrian prints

buy adjustable air bed
buy the best adjustable air beds

air bedscanadian stores
air beds, cheap canadian stores

4:36 AM  
Anonymous Anonymous said...

紅酒,
Quality Wine,
Terrior Wine,
Riesling Wine
搬屋,
物流公司,
搬屋公司,
包裝公司,
搬屋服務
搬寫字樓,
Office Relocation,
搬屋公司,
運輸公司,
搬運服務
購物袋,
包裝袋,
不織布袋,
Non Woven Shopping Bag,
Recycle Bag,
Wine Bag
辦公室傢俬,
僱傭中心,
寫字樓傢俬,
辦公室屏風,
Office Furniture,
Storage Rack,
成立公司,
商業登記,
稅務顧問,
Accounting Service

4:59 AM  

Post a Comment

Links to this post:

Create a Link

<< Home