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.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/26/using-the-flash-classes-in-mxml/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        xmlns:flash.filters="flash.filters.*"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Array id="filterArray">
        <flash.filters:DropShadowFilter id="dropShadowFilter"
                angle="90"
                blurX="5"
                blurY="5"
                  distance="2"
                  alpha="0.9"
                  color="0xFF0000" />
          <flash.filters:BlurFilter id="blurFilter"
                  blurX="3"
                  blurY="3"
                  quality="3" />
    </mx:Array>

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

</mx:Application>

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,
    Peter

    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.
    Code:FontSkin.as
    package
    {
    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 FontSkin.as 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.