Using a custom flex-config.xml file in Flex Builder 3

by Peter deHaan on December 21, 2008

in Compiler, Flex Builder, Flex Builder 3, Fonts

The following example shows how you can use a custom configuration file in a Flex Builder Flex project by specifying an additional compiler argument, -load-config.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/12/21/using-a-custom-flex-configxml-file-in-flex-builder-3/ -->
<mx:Application name="LoadConfig_fonts_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        @font-face {
            src: url("assets/ARIAL.TTF");
            fontFamily: "ArialEmbedded";
            unicodeRange: "englishRange";
        }

        Text {
            fontFamily: "ArialEmbedded";
            fontSize: 32;
            color: red;
        }
    </mx:Style>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="alpha:">
                <mx:HSlider id="slider"
                        minimum="0.0"
                        maximum="1.0"
                        value="1.0"
                        snapInterval="0.05"
                        tickInterval="0.1"
                        liveDragging="true" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Text id="txt" width="300" alpha="{slider.value}">
        <mx:text>The quick brown fox jumps over the lazy dog. 1234567890 ©</mx:text>
    </mx:Text>

</mx:Application>

Next, create a custom configuration XML file named fontConfig.xml and save it in a /config/ subdirectory in your project’s /src/ directory. The folder structure isn’t important, but it helps keep the source code and configuration files separated. The fontConfig.xml file is a modified version of the flex-config.xml file found in the Flex SDK’s /frameworks/ directory. In this example we simply specify a single named font range which specifies a unicode range of U+0020 (space) to U+007E (~).

config/fontConfig.xml

<?xml version="1.0"?>
<flex-config>
   <compiler>
      <fonts>
          <!-- Defines ranges that can be used across multiple font-face declarations. -->
          <!-- See flash-unicode-table.xml for more examples. -->
          <languages>
              <language-range>
                  <lang>englishRange</lang>
                  <range>U+0020-U+007E</range>
              </language-range>
          </languages>
      </fonts>
   </compiler>
</flex-config>

Finally, in Flex Builder, right click on the Flex Project folder in the Flex Navigator and select Properties from the context menu. Select the Flex Compiler section of the dialog menu and in the Additional compiler arguments: text box add the following text:

-load-config+=config/fontConfig.xml


Figure 1. Additional compiler arguments.

View source is enabled in the following example.

{ 12 comments… read them below or add one }

1 Alan December 21, 2008 at 5:26 pm

What could I use this for, I’ve only used the config file for my RPC service gateways. What can custom file do for a Flex dev?

Reply

2 Peter deHaan December 21, 2008 at 6:31 pm

Alan,

I’d use it for specifying a custom unicode range. You may not want to edit the Flex SDK’s flex-config.xml globally so using load-config with a custom config file would let you have an external config file which you could check into an SVN repository and share with other developers on a Flex project if you wanted have a client/project specific compiler settings.

Peter

Reply

3 Adam Bankin December 23, 2008 at 12:02 am

Hmmmm, useful. Saves a bit of time in the round trip to Flash to make and embed a dynamic font swf. Do you know the syntax for adding individual unicode values to the range node? Is it just commas between values/sets of ranges or do you need to add more nodes?

Reply

4 mark joseph February 10, 2009 at 4:08 am

Hi, I know that this is not the right topic for my problem, I just want to ask how to integrate a file in my application (built using adobe flex builder 3). This is my Problem:

I created an application using adobe flex builder 3.
I already build it and install it in my computer
I created an icon for fileType

and it works… when I double clicked the file with extension name ‘.mjm’ (.mjm is the file type I’ve set on app.xml), the application that I created open, but the file that I clicked din’t load its content on the application.

Is there any code for this problem?

Thanks in advance

Reply

5 chaitra May 12, 2009 at 5:06 am

Hi Peter,

This really very good example but when i am trying the same example in my Flex builder Workspace its throwing an error like “unable to resolve ‘assets/ARIAL.TTF’ for transcoding” please give me a suggestion on this issue.

Thanks in advance,
Chaitra H.

Reply

6 Peter deHaan May 12, 2009 at 6:56 am

chaitra,

Make sure you have a assets/ARIAL.TTF in your project. Also, if you are using Mac or Linux, the filenames will be case sensitive, so make make sure that the file name is ARIAL.TTF (uppercase), or change the code to match whatever case the font name is on your machine.

Peter

Reply

7 Pauli October 13, 2009 at 4:47 pm

I wanted to share a few observations relative to the 3.4 sdk and the Eclipse plugin of Flex Builder 3 (Mac OS X) –

Apparently a variant of this bug: https://bugs.adobe.com/jira/browse/SDK-21156 — “Library Project namespaces should be appended by default” exists in this environment. In particular, when using degrafa within a “Flex Library Project” rather than a regular “Flex Project” the following would not compile:

 

It generated a “Could not resolve to a component implementation. ” error.

Explicitly including the library in a config file, as per your example, fixed the problem. However, I had to include the full rooted path to the config file in the Project Properties Library Compiler settings, as follows:

-load-config+=/Users/username/Documents/workspace/projectname/src/config.xml

Also, since the file was in src, the library file had to be specified in the config.xml as:

<library>../libs/DegrafaLibrary.swc</library>

Shared in the interest of Google helping the next poor soul who hits this problem — and to offer another motivation for using this technique.

Reply

8 Pauli October 13, 2009 at 4:48 pm

Well the pre tags didn’t work — the code that wouldn’t compile is:

<degrafa:GeometryGroup
xmlns:mx=”http://www.adobe.com/2006/mxml”
xmlns:degrafa=”http://www.degrafa.com/2007″
xmlns:geometry=”com.degrafa.geometry.*”>

Reply

9 ash December 7, 2009 at 11:18 pm

Are you sure this is working? If I add

400
400

it has no effect. I’ve also tried:

report.xml

and no file is generated. Of course, if I add these options to the project properties, it works.
Am I missing something?

Reply

10 ash December 7, 2009 at 11:21 pm

Lol. I guess I should read the big red sign before posting! Let’s try that again…

&ltdefault-size&gt
&ltwidth&gt400&lt/width&gt
&ltheight&gt400&lt/height&gt
&lt/default-size&gt

&ltlink-report&gtreport.xml&lt/link-report&gt

Reply

11 ash December 7, 2009 at 11:24 pm

Third time is the charm…

<default-size>
<width>400</width>
<height>400</height>
</default-size>

<link-report>report.xml</link-report>

Reply

12 Andreas Falley February 1, 2010 at 1:29 pm

Is there a way to customize the default application file that gets created when you create a new project? For instance, if for every future project I create I’d like to have some custom comments or Application properties (additional namespaces, height, width etc. set to particular defaults ) generated along with the usual look and feel of the Application tag in an initially generated file in the ide (either Flex 3 or Flash Builder) and/or when a New Application menu item is selected?

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: