Using the flash.* classes in MXML

I saw this trick the other day and thought it was pretty handy, so thought I’d save it here for future reference.

The following example shows how you can use the flash.filters classes in your MXML code by creating a new XML namespace.

Full code after the jump.


<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<mx:Application xmlns:mx=""

    <mx:Array id="filterArray">
        <flash.filters:DropShadowFilter id="dropShadowFilter"
                  color="0xFF0000" />
          <flash.filters:BlurFilter id="blurFilter"
                  quality="3" />

    <mx:Label text="{flash.system.Capabilities.version}"
            filters="{filterArray}" />


View source is enabled in the following example.

5 thoughts on “Using the flash.* classes in MXML

  1. peterd,
    today, my boss told me that”Do not binding font in the swf”, so i have to load a external font from the server.
    Now, i spend a long time to solve it.
    Although, i didn’t know why? Why not binding a new font in the swf(while it will be larger)?

    BTW, my english is pool.Sorry;(

  2. dormouse,

    I don’t know of any reasons to do one or the other (not that there aren’t valid reasons, I just don’t know why one method is preferable to the other). I did have an entry on using fonts from a SWF in an MXML application, but it has been in my drafts for a month or so now. I’ll see if I can dig that up.

    In the meantime, check out the Adobe Flex 2 Developer’s Guide documentation on LiveDocs, “Using Fonts”. And more specifically, this section “Embedding fonts from SWF files”.

    Hope that helps,

    PS: Any readers out there care to educate me on why fonts embedded in SWFs are preferable to TTF fonts embedded in MXML?

  3. peterd

    Thanks, i have saw the Adobe Flex 2 Developer’s Guide documentation. In it, using flash 8 to create swf with embedded fonts. But i use mxmlc order to create it.
    import flash.display.Sprite;

    public class FontSkin extends Sprite
    [Embed(mimeType=’application/x-font’, source=’xujinglei.fon’, fontName=’handFont’)]
    public var MyFont:Class;
    then in the console input mxmlc to create swf.
    It is my first to write, there is any things wrong?Can you give me some tips, Thanks for your applys

Comments are closed.