Compile a Flex CSS file into a SWF using the command line - apache-flex

I understand that in Flex builder we can right click on a CSS file and choose 'compile to swf' and our CSS SWFs will automatically be compiled along with the main app.
Is possible to compile the CSS file only (not with the main app) from the command line?
I want to :
Give clients a Flex CSS file to hand edit
Allow them to upload the file via a CMS
Trigger a server process to run the compiler from the command line, outputting the compiled SWF to the appropriate server path.
This would of course be a whole lot simpler if Flex properly supported text-based CSS files (without requiring manually applying styles using AS3).

Yes, it is possible and really easy just type:
mxmlc yourFIle.css
at the command prompt

Related

How to combine css file and xml file with a GTK3 project

I am using external css to theme my GTK3 application (on windows 7, 64bits)
also I am using xml file that describes all the widgets in the application
both of these two files (.css & .xml) are used during runtime of my application (.exe)
my question: how to compile my application so that it will no longer depend on the css and xml files ?
Put the files inside a GResource and compile them directly into your program.
The documentation explains it well enough, but basically you generate a resource.c and resource.h file during your build process, that encode the external files. Then you compile those files into your program, and they will be available through a URI such as resource:///com/example/yourprogram/yourwidgets.xml.

Embed external CSS in Flex's swf file

I want a few Flex (SDK 4.6) applications to share the same stylesheet (stored in CSS file). However I do not want to distribute standalone file along those applications' SWFs, but rather want to embed the CSS file into Flex application file (just as you embed images etc.). CSS declarations include font-embeddings so it is (I think) impossible to load CSS at runtime.
What I already found out:
I cannot simply use <fx:Script source="#Embed(stylesheet.css)" />. Wrong syntax.
I cannot use inline stylesheet in some MXML component that is shared among applications because CSS contains type declarations which are not allowed in components.
I can choose to compile CSS to SWF but this creates standalone SWF file (so I can embed Flex framework into SWF but not a standalone CSS ;]).
I hope I am missing something obvious and this is fairly easy to achieve.
Create a library project (producing a swc file)
Add the stylesheet as a resource
Put this project (or the compiled swc) on your other project's build path
You can now use this resource from within your other projects:
<fx:Style source="stylesheet.css" />
As an example:
In the librabry project you have src/stylesheet.css
If src is a source folder, the file should automatically be packaged into the library
If it's not, you'll have to manually add the files: in FlashBuilder this can be done through the Assets tab of the Build path editor. On the command line, add it with the -include-file option.
An alternative to using the swc as a library dependency, is to define it as a theme dependency. In FlashBuilder there's a Theme wizard in the project properties. On the command line do:
mxmlc -theme="/path/to/my/theme.swc" MyApp.mxml
If you use it as a theme, you don't even have to include the fx:Style tag in your Application. The CSS is included by default. But I think it has to be named defaults.css.

How do I make LessCSS output css which is then uploaded to webserver

I want to use LessCSS for some of its benefits, but I don't want the user to have to download the less.js file or have it do any processing client side - I don't even want to have LessCSS working on my webserver. I'd like to write some Less, push it through LessCSS and then upload the resulting CSS file to the webserver.
Ideally I'd like LessCSS to process the Less file as when I save it in NetBeans and automagically pop out a css file.
Any ideas where to start?
Have a look at my blog entry (http://blog.nickdamoulakis.com/2012/04/php-less-css-and-cssjs-minify.html) where I list and describe a method I use.
Basically, I have a tab open in my browser that points to my compile.php.
Whenever I want to 'compile' files, I just press F5 and it compiles JS-->MIN.JS, LESS-->CSS and CSS-->MIN.CSS.
An INI file specifies which directories to process.
It is not a fully automated process but it works for what I need it to do.
I hope it is of use to you.
Check out SimpLESS. It's a standalone application, but it will monitor a folder for changes in .LESS files and auto compile them into CSS.

Change mxmlc from swf to html on ubuntu

When I use mxmlc to compile my mxml file, I get swf file. Now, I want to change the config to make mxmlc compiler generate html file instead, as we can do in Eclipse or Flex Builder. Any solution? Thanks!
You can't do this. From the documentation:
The mxmlc command-line compiler does
not generate an HTML wrapper. You must
create your own wrapper to deploy a
SWF file that the mxmlc compiler
produced. The wrapper is used to embed
the SWF object in the HTML tag. It
includes the <object> and <embed>
tags, as well as scripts that support
Flash Player version detection and
history management.
Of course, the HTML wrapper is pretty much all boilerplate, apart from the name of the .swf file it wraps. You could create one for a project at the beginning by copying an existing one and changing the .swf-file reference, and that should be good enough most of the time.
You should use an ant task to build your project. Flex Ant tasks include a html-wrapper task that generates that html. See "Using the html-wrapper task".

Post Build Actions in Flex Builder

How do I add post-build actions in Flex Builder? For example, I'd like my build to work as normal, and execute from the bin folder; but I'd also like a copy of the final SWF to be copied to another folder automatically (I'm sick of doing it myself).
Thanks!
I know this post has been answered, but I found something simpler. I'm sure the Ant solutions are the way to go, but I didn't feel like messing with ant for my small project. All I really want is to have my html files and swf files in different directories. I guess that's a lot to ask.
I'm building on windows, so I created a simple batch file that performs my post-build steps (namely some move commands). I then created a new builder in flex using windows cmd.exe. I just told it to call the batch file using the /C option. It works perfectly and was very simple to set up. I tried adding screen shots, but I guess I'm too new to the site.
You can extend or replace the builder used by Flex Builder 3 with extenal programs - ant is a good choice.
If you run "Flex Builder 3 standalone" (which is a minimalist Eclipse version + the Flex builder plugin) as opposed to the Flex builder plugin in a standard Eclipse, you first need to install ant support. I didn't find ant separately packaged, so I just selected the Java build environment from Help / Software Updates.
Now you can go to your project properties (Right-Click on your Project, Properties) and chose Builders. You'll notice there is a Flex Builder per default, which you cannot remove nor change. However, you can deselect it and you can add other builders.
So in your case: "add" a new builder, ant builder, select a build.xml (can be named differently), preferably from within your project folder, and set the correct targets. This will continue to use the internal IDE builder while running your ant task just before or afterwards. The ordering on the screen will be the build order, which you can change using the arrow buttons.
I used this to copy required libraries into my /lib folder, compile the Flex sources using the IDE build (which has Eclipse-integration with error messages, which a pure ant-based commandline build would miss), and copy the result to a common deploy directory, renaming the wrapper html file in this process.
For details of how to write an ant file, please refer to the ant documentation.
I would also recommend using ant.
I posted a big article on how to get it set up for flexbuilder here http://dispatchevent.org/mims/ant-for-flex-part-1/ I think there is even an example in my build script of copying files from one place to another after compiling.
Good luck!
You'll have to create a custom build script. For whatever reason, the included, default 'builder' is not editable through the interface, so you'll have to replicate a lot of its functionality. Luckily, (or maybe not) Flex Builder uses Apache Ant for its build scripts, so this may or may not be a familiar way to do this for you.
To create a custom build script:
In the Flex Navigator view, select a project and then right-click (Control-click on Macintosh) to display the context menu and select Properties.
Select the Builders properties page. If you're using other Eclipse plug-ins, there may be more than one builder listed. Flex Builder provides a builder named Flex, which you cannot modify.
Select New.
In the Choose Configuration Type dialog box, select the appropriate configuration type. Flex Builder supports the program type. Select it and click OK to continue. From the new builder properties page you define the builder properties and reference the Ant script (an XML file).
Click OK to apply it to the project.
Flex builder is based on Eclipse 3.1, so documentation for Ant integration for that release is relevant here.
Note: Ant support must be enabled in Flex Builder first. I usually use Flex Builder as a plugin, rather than the standalone version, and the standalone version doesn't come with it out of the box. Here's a tutorial on how to do this.
Steve,
If you want use Ant in Flex Builder, you may see:http://www.peterelst.com/blog/2006/09/03/flex-builder-2-ant-support/
but I am not sure this is work in flex builder 3 or not.
Steve,
Here is a bit more detail on the post build script. It will be a simple bat file. For instance add the below line to a simple text file postbuild.bat (name doesn't matter).
copy bin/*.* 'someother location'
This would copy everything in the bin folder to another folder, just change the 'someother location'.
The least elegant solution but it will work on linux.
Create cron task to be executed every minute.
Use cp command with "-u" option.
From "man cp".
-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
In crontab -e add
* * * * * cp -u /path/to/bin-debug/*.swf /path/to/destination/
For more elegant solution - Ant the way to go.

Resources