views:

163

answers:

2

Hey guys,

This is a really strange one. I've created my own CustomTextField class which I am using to embed the font and set the defaultTextFormat. This is working absolutely fine, but for some reason when I try to create a new CustomTextField in any module but the parent application, text text is only showing sometimes.

Here is my CustomTextField class:

package uk.package.text
{
    import flash.text.AntiAliasType;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    public class CustomTextField extends TextField
    {

        [Embed(source='../assets/fonts/Arial.ttf',fontName='CustomFont',fontWeight='regular',
            unicodeRange='U+0020-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E,U+0080-U+00FF,U+0100-U+017F,U+0400-U+04FF,U+0370-U+03FF,U+1E00-U+1EFF',
            mimeType='application/x-font-truetype'
            )]
        public static var MY_FONT:Class;
        [Embed(source='../assets/fonts/Arial Bold.ttf',fontName='CustomFont',fontWeight='bold',
            unicodeRange='U+0020-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E,U+0080-U+00FF,U+0100-U+017F,U+0400-U+04FF,U+0370-U+03FF,U+1E00-U+1EFF',
            mimeType='application/x-font-truetype' 
            )]
        public static var MY_FONT_BOLD:Class;

        public static const DEFAULT_FONT:String = "Arial";
        public static const DEFAULT_TEXT_COLOUR:int = 0x000000;
        public static const DEFAULT_TEXT_SIZE:int = 14;

        private var _tf:TextFormat = new TextFormat(DEFAULT_FONT, DEFAULT_TEXT_SIZE, DEFAULT_TEXT_COLOUR);

        public function CustomTextField():void
        {
            var CustomFont:Font = new MY_FONT();
            _tf.font = CustomFont.fontName;
            _tf.size = 16;

            embedFonts = true;
            antiAliasType = AntiAliasType.ADVANCED;
            defaultTextFormat = _tf;
            autoSize = TextFieldAutoSize.LEFT;
        }

        public override function set htmlText(value:String):void
        {
            super.htmlText = value;
            setTextFormat(_tf);
        }

        public function get textFormat():TextFormat
        {
            return _tf;
        }

    }
}

It's weird how sometimes it works and sometimes it doesn't... perhaps there is something odd going on with the modules?

+1  A: 

yes it's almost definitely a module issue. I've seen something similar before. I'm searching out the answer but my initial thought is to set

moduleLoader.applicationDomain = ApplicationDomain.currentDomain

Another issue is if you're loading the same module twice. If so you need to make the url unique by adding file.swf?<randomNumber> or something similar.

susichan
I've tried both of these, still experiencing the problem though. If you do manage to rook out the answer, it'd be very grateful!
Hanpan
A: 

Ok, this one took me ages to figure out. I finally got it working by using the following code:

preinitialize="moduleLoader.moduleFactory=Application.application.systemManager;"

In the module loader item.

Thanks!

Hanpan