Embed external CSS in Flex's swf file - css

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.

Related

How to specify linked resource folder in mxmlc compiler arguments?

I've got external folder with resources (graphics, movies, etc) which is shared between a couple of projects. I'm able to link this resource folder in FlashBuilder (as described in http://livedocs.adobe.com/flex/3/html/help.html?content=projects_5.html#155069). After that all the pathes to embeds are relative to the project, and that's the behaviour I want.
This linked resource appears in .project file as follows:
<linkedResources>
<link>
<name>resources</name>
<type>2</type>
<locationURI>DOCUMENTS/Shared/resources</locationURI>
</link>
</linkedResources>
Note, that it isn't source folder and it is not included in compilerSourcePath tag.
The question is how can I specify resource linked folder in mxmlc command line arguments?
-source-path is not working here, relative pathes to embeds can not be resolved.
Seems like it's not possible and there's no such option. FlashBuilder somehow passes all the workaround to mxmlc java wrapper, therefore it knows where to search resources.
In my project I used another method to achieve proper sharing of resources:
Autobuild step, which copies images and extractes fla files to resource folder in each project form the source directory.
All css files I moved to shared source folder (e.g. Common/css/main.css) - they are under source control. I added link to it via -source-path option.
After that all relative pathes in css started to look like ../../resources/image.png in both projects.
Maybe someone will find my experience helpful.

Flex and Ant: How do I include other folders via ant script?

I currently have a Flex project that was done in Eclipse, using the following compiler settings:
Flex Build Path: (Source Path) includes source folders from other areas, i.e common_components, which aren't projects on their own but just folders with various code I need to share. This works fine but I want to migrate to using ant.
I have read in places on how to include libraries, via compiler.include-libraries, but as this isn't a library but rather just bunch of folders with .as and MXML files, how do i accomplish this?
You want to look into adding source paths so that the compile can look at more than one place for your classes. You can do that by adding new compiler options.
The compiler option you're looking for is source-path path-element [...].

Adding Flex Modules

Is it possible to add multiple Flex Modules at a time to be built in a project as opposed to adding them one by one, as this is becoming a very tedious task.
This is for both Eclipse and Flash Builder 4
You cannot add multiple modules through Flash Builder as far as I'm aware. The dialog is only for one-at-a-time.
You can, however, add them yourself via the .actionScriptProperties file located in your project's root folder (you have to browse via explorer to see it).
Under the <modules> node, add as many of the following elements as needed:
<module application="src/YourMainApp.mxml" destPath="com/modules/yourModule.swf" optimize="true" sourcePath="com/modules/yourModule.mxml"/>
The destPath determines where the module will be located in the published directory structure. The sourcePath is the path within your project to your module's MXML file. Both of these are relative to the main app's location.

Compile a Flex CSS file into a SWF using the command line

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

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".

Resources