Results 1 to 6 of 6
  1. #1

    Lightbulb AS2/AS3 - Embedding Fonts to be Used by a Dynamically Created TextField

    If you wish to create a textfield on the fly in code, and have it use a specific font, use the following method:

    Step 1 (Flash CS5)


    1. Right click the in the library panel, and choose New Font.
    2. In the Font Embedding window, click the + icon to create a new font. (found at the top, above the list of fonts)
    3. On the Options panel, change the font name (optional).
    4. Choose the font family.
    5. Choose the font style.
    6. Under Character ranges, check 'Basic Latin'.
    7. On the ActionScript panel, put a check in 'Export for ActionScript'.
    8. Press OK.








    ActionScript 2.0 Version

    Step 2 (ActionScript 2.0)

    First, create a new text format that uses the new font. In this case, I named my Font "CoolFont"

    Code:
    var myFont:TextFormat = new TextFormat();
    myFont.size = 30;
    myFont.font = "CoolFont";
    Now, you can dynamically create the text field, and set it to use the embedded font:

    Code:
    createTextField("dynamic_txt", 2, 10, 40, 150, 30);
    dynamic_txt.setNewTextFormat(myFont);
    dynamic_txt.embedFonts = true;
    Then, you can set other options:

    Code:
    dynamic_txt.textColor = 0x00cc00;
    // etc...
    Finally, set up the text field so that it fires off a WidgetInitialzied() event.

    Code:
    if( _global.CLIK_loadCallback )
    {
    	_global.CLIK_loadCallback(dynamic_txt._name, targetPath(dynamic_txt), dynamic_txt);
    }

    Save and Publish the SWF file.
    Then import it into UDK.



    Step 3 (UnrealScript)

    First, declare a variable for the text field:

    Code:
    var GFxObject DynamicTF;
    Next, set the text field up in the WidgetInitialized() event function:

    Code:
    event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
    {    
        switch(WidgetName)
        {                 
            case ('dynamic_txt'):
    	    DynamicTF = Widget;
    	    SetWidgetPathBinding(DynamicTF, WidgetPath);
    	    DynamicTF.SetString("text", "It works! 123");
            default:
                break;
        }
        return true;
    }
    Last of all, add a WidgetBindings line to your defaultproperties for the text field:

    Code:
    defaultproperties
    {	
        WidgetBindings(0)={(WidgetName="dynamic_txt",WidgetClass=class'GFxClikWidget')}
        ...
    }
    Rebuild scripts, and run your level/HUD to test it out.





    ActionScript 3.0 Version

    Step 2 (ActionScript 3.0)

    First, we'll need to modify CLIK.as, found here: C:\UDK\UDK-2012-01\Development\Flash\AS3\CLIK\scaleform\clik\core
    NOTE: This is a bit of a hack, and will be fixed in a future version so that you don't have to do this step.

    Find the function getTargetPathFor, around line 85, and change its parameter:

    from:

    Code:
    (clip:DisplayObjectContainer)
    to:

    Code:
    (clip:DisplayObject)
    Then, save this file.

    Next, back in our UI Flash file, we need to add two import statements:

    Code:
    import scaleform.gfx.Extensions;
    import scaleform.clik.core.CLIK;
    Now create a new text format that uses the new font. In this case, I named my Font "CoolFont"

    Code:
    var myFont:TextFormat = new TextFormat();
    myFont.size = 30;
    myFont.font = "CoolFont";
    Now, you can dynamically create the text field, and set it to use the embedded font:

    Code:
    var myTextField:TextField = new TextField();
    myTextField.embedFonts = true;
    myTextField.defaultTextFormat = myFont;
    
    addChild(myTextFieldMC.myTextField);
    
    myTextFieldMC.myTextField.name = "dynamic_txt";
    Then, you can set other options:

    Code:
    myTextFieldMC.myTextField.width = 250;  
    myTextFieldMC.myTextField.x = 25;  
    myTextFieldMC.myTextField.y = 25; 
    // etc...
    Finally, set up the text field so that it fires off a WidgetInitialized() function. This is not necessary for CLIK text fields, but only standard Flash textfields.

    Code:
    if( Extensions.CLIK_addedToStageCallback != null)
    {
    	Extensions.CLIK_addedToStageCallback(myTextFieldMC.name, CLIK.getTargetPathFor(myTextFieldMC), myTextFieldMC);
    }



    Save and Publish the SWF file.
    Then import it into UDK.



    Step 3 (UnrealScript)

    First, declare a variable for the text field:

    Code:
    var GFxObject DynamicTF;
    Next, set the text field up in the WidgetInitialized() event function:

    Code:
    function WidgetInit(string WidgetName, string WidgetPath, GFxObject Widget)
    {    
        switch(WidgetName)
        {                 
            case ("dynamic_txt"):
    	    DynamicTF = Widget;
    	    SetWidgetPathBinding(DynamicTF, name(WidgetPath));
    	    DynamicTF.SetString("text", "It works! 123");
            default:
                break;
        }
    }
    Last of all, add a WidgetBindings line to your defaultproperties for the text field:

    Code:
    defaultproperties
    {	
        WidgetBindings(0)={(WidgetName="dynamic_txt",WidgetClass=class'GFxClikWidget')}
        ...
    }
    Rebuild scripts, and run your level/HUD to test it out.
    Last edited by Matt Doyle; 02-10-2012 at 03:46 PM.

  2. #2

    Default

    What about with ActionScript 3.0? It appears you cannot use an identifier with font embedding.

  3. #3

    Default

    AS3 version added to tutorial.

  4. #4

    Default

    When following the actionscript 2 method, I still get this warning:
    Warning: Warning, Failed to load 'Font None.Times New Roman': Failed to find object 'Font None.Times New Roman'

  5. #5

    Default

    Quote Originally Posted by Scaredhelmet View Post
    When following the actionscript 2 method, I still get this warning:
    Warning: Warning, Failed to load 'Font None.Times New Roman': Failed to find object 'Font None.Times New Roman'
    Has anyone ever figured out how to get rid of this Times New Roman warning in UE3 for the AS2 version?

  6. #6

    Default

    If that's just a warning that happens once or a couple times and not every tick/call and also doesn't case a problem in the game, just ignore it.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.