Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Font Embedding

Explorer ,
Apr 19, 2010 Apr 19, 2010

I have a program and use there dynamic text. For this text i use special font CAMPFIRE.ttf.

A lot of users dont have this font on their pc but i want then they open my .swf and see this font.

For this i use next code:

var fooFont:foo = new foo();
               var format:TextFormat = new TextFormat();
               format.font=fooFont.fontName;
               format.color=0xFF0000;
               format.size = 100;
               levelNumbers.height += 100;
               levelNumbers.embedFonts=true;
               levelNumbers.autoSize = TextFieldAutoSize.CENTER;
               levelNumbers.antiAliasType=AntiAliasType.ADVANCED;
               levelNumbers.defaultTextFormat=format;

but i dont see my dynamic text correct. I see strange space on top, also dont see bottom part of text.

pic preview:

e.png

Can anybody help please or offer any other way how to do main idea what i need?

All code here:

package {

     import flash.events.*;
     import flash.display.*;
     import flash.text.TextField;
    
     import flash.text.TextFormat;
     import flash.text.TextFieldAutoSize;
     import flash.text.AntiAliasType;

     public class GuessNumber extends MovieClip
     {
          var guessNumber:Number;
          var points:Number = 0;    
          var level:Number = 1;
          var lastGuessNumber:Number = 5;
         
          //constructor
          public function GuessNumber()
          {
               beginScreen();
          }
         
          public function beginScreen():void
          {
               gotoAndStop('beginScreen');
               playBtn.addEventListener(MouseEvent.CLICK, startGame);
              
               howToPlay_mc.visible = false;
               moreGames_mc.visible = false;
               thanks_mc.visible = false;
              
               howToPlayBtn.addEventListener(MouseEvent.CLICK, howToPlayScreen);
               moreGamesBtn.addEventListener(MouseEvent.CLICK, moreGamesScreen);
               thanksBtn.addEventListener(MouseEvent.CLICK, thanksScreen);
          }
         
          public function startGame(event:MouseEvent):void
          {
               generateNumber();
          }
         
          public function generateNumber(e:Event = null):void
          {
               gotoAndStop('gameScreen');
               trace("****** Welcome Screen *********");
               pointsView.text = "0";
               levelView.text = "1";
               addEventListener(Event.ADDED_TO_STAGE, startGuess);
               startGuess();
          }
         
          public function howToPlayScreen(event:MouseEvent):void
          {
               trace("Open 'How to play screen'");
               howToPlay_mc.closeBtn.addEventListener(MouseEvent.CLICK, closeHowToPlayScreen);
              
               howToPlayBtn.mouseEnabled = false;
               moreGamesBtn.mouseEnabled = false;
               thanksBtn.mouseEnabled = false;
              
               howToPlayBtn.alpha = 1;
               moreGamesBtn.alpha = 0.5;
               thanksBtn.alpha = 0.5;
              
               howToPlay_mc.visible = true;
               moreGames_mc.visible = false;
               thanks_mc.visible = false;
          }
          public function moreGamesScreen(event:MouseEvent):void
          {
               trace("Open 'More games screen'");
               moreGames_mc.closeBtn.addEventListener(MouseEvent.CLICK, closeMoreGamesScreen);
              
               howToPlayBtn.mouseEnabled = false;
               moreGamesBtn.mouseEnabled = false;
               thanksBtn.mouseEnabled = false;
              
               howToPlayBtn.alpha = 0.5;
               moreGamesBtn.alpha = 1;
               thanksBtn.alpha = 0.5;
              
               howToPlay_mc.visible = false;
               moreGames_mc.visible = true;
               thanks_mc.visible = false;
          }
          public function thanksScreen(event:MouseEvent):void
          {
               trace("Open 'Thanks screen'");
               thanks_mc.closeBtn.addEventListener(MouseEvent.CLICK, closeThanksScreen);
              
               howToPlayBtn.mouseEnabled = false;
               moreGamesBtn.mouseEnabled = false;
               thanksBtn.mouseEnabled = false;
              
               howToPlayBtn.alpha = 0.5;
               moreGamesBtn.alpha = 0.5;
               thanksBtn.alpha = 1;
              
               howToPlay_mc.visible = false;
               moreGames_mc.visible = false;
               thanks_mc.visible = true;
          }
          public function closeHowToPlayScreen(event:MouseEvent):void
          {
               howToPlay_mc.visible = false;
               trace("Close 'How to play screen'");
              
               howToPlayBtn.mouseEnabled = true;
               moreGamesBtn.mouseEnabled = true;
               thanksBtn.mouseEnabled = true;
              
               howToPlayBtn.alpha = 1;
               moreGamesBtn.alpha = 1;
               thanksBtn.alpha = 1;
          }
          public function closeMoreGamesScreen(event:MouseEvent):void
          {
               moreGames_mc.visible = false;
               trace("Close 'More games screen'");
              
               howToPlayBtn.mouseEnabled = true;
               moreGamesBtn.mouseEnabled = true;
               thanksBtn.mouseEnabled = true;
              
               howToPlayBtn.alpha = 1;
               moreGamesBtn.alpha = 1;
               thanksBtn.alpha = 1;
          }
          public function closeThanksScreen(event:MouseEvent):void
          {
               thanks_mc.visible = false;
               trace("Close 'How to play screen'");
              
               howToPlayBtn.mouseEnabled = true;
               moreGamesBtn.mouseEnabled = true;
               thanksBtn.mouseEnabled = true;
              
               howToPlayBtn.alpha = 1;
               moreGamesBtn.alpha = 1;
               thanksBtn.alpha = 1;
          }
         
          public function startGuess(e:Event = null):void
          {
               trace("**** Starting Guess ****");
               guessBtn.enabled = true;
               guessBtn.visible = true;
               nextLevelBtn.enabled = false;
               nextLevelBtn.visible = false;
              
               var fooFont:foo = new foo();
               var format:TextFormat = new TextFormat();
               format.font=fooFont.fontName;
               format.color=0xFF0000;
               format.size = 100;
               levelNumbers.height += 100;
               levelNumbers.embedFonts=true;
               levelNumbers.autoSize = TextFieldAutoSize.CENTER;
               levelNumbers.antiAliasType=AntiAliasType.ADVANCED;
               levelNumbers.defaultTextFormat=format;
              
               levelNumbers.text = String(lastGuessNumber);
               trace("Guessed number beetween 1 and " + lastGuessNumber);
               yourGuessText.text = "";
               levelView.text = String(level);
               trace("Now Level: " + level);
               pointsView.text = String(points);
               trace("Player Points: " + points);
              
               guessNumber=Math.ceil(Math.random()*lastGuessNumber);
               trace("Guessed number: " + guessNumber);
              
               removeEventListener(Event.ADDED_TO_STAGE,startGuess);
               guessBtn.addEventListener(MouseEvent.CLICK,checkingYourGuess);
          }
         
          public function checkingYourGuess(e:MouseEvent):void
          {
               if (yourGuessText.length == 0)
               {
                    trace("need enter something");
                    outputText.text="please enter a number beetween 1 and " + lastGuessNumber;
                    return;
               }              
              
               if (guessNumber == Number(yourGuessText.text))
               {
                    outputText.text = "You are GUESS!!!";
                    trace("Guess!");
                    points += 100;
                    trace("Player earn: " + points + " points!");
                    trace("+++++++++++++++++++++++++");
                    trace("go to the next level?");
                    nextLevelBtn.visible = true;
                    guessBtn.visible = false;
                    winGame();
               }
               else if (guessNumber > Number(yourGuessText.text))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need MORE");
                    outputText.text = "need MORE, try again please";
               }
               else if (guessNumber < Number(yourGuessText.text) && (Number(yourGuessText.text)<= lastGuessNumber))
               {
                    points -= 20;
                    pointsView.text = String(points);
                    trace("-20 points, need LESS");
                    outputText.text = "need LESS, try again please";
               }
               else if (Number(yourGuessText.text) > lastGuessNumber)
               {
                    outputText.text = "enter number from 1 to " + lastGuessNumber;
                    trace("enter number from 1 to " + lastGuessNumber);
               }         
          }
         
          public function winGame():void
          {
               pointsView.text = String(points);
               level += 1;
               if (level == 4)
               {
                    youAreWinner();
                    trace("You are winner!!!!!");
                    pointsView.text = String(points);
                    trace("Player earn: " + points + " points." );
                    level = 1;
                    points = 0;
                    lastGuessNumber = 5;
               }
               else{lastGuessNumber += 10;}
              
               nextLevelBtn.enabled=true;
               guessBtn.enabled=false;
               nextLevelBtn.addEventListener(MouseEvent.CLICK, playAgain);
          }
         
          public function playAgain(event:MouseEvent):void
          {
               trace("yes");
               outputText.text = "";
               startGuess();
          }
         
          public function youAreWinner():void
          {
               gotoAndStop('finishScreen');
               nextLevelBtn.visible = false;
               guessBtn.visible = false;
               playAgainBtn.addEventListener(MouseEvent.CLICK, generateNumber);
          }
         
     }

}

TOPICS
ActionScript
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 19, 2010 Apr 19, 2010

that's not a font embedding problem.

make sure multiline is disabled.

Translate
Enthusiast ,
Apr 19, 2010 Apr 19, 2010

You can embed the font in library and use it from there, by giving linkage name.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

i dont see linkage name

where i can find it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2010 Apr 19, 2010

you don't use a linkage id in as3.  you assign a class to your font.

in your library, you should have added your font.  did you?  if so, right click on your font, click linkage or properties, tick export in frame 1 and assign it the class, foo

then change your code from:

var fooFont:foo = new foo();

to

var fooFont:Font = new foo();
              
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

for kglad

yes, i make like you told

but when i change type from foo to Font i see error:

153: 1046: Type was not found or was not a compile-time constant: Font.

line 153 this is: var fooFont:Font = new foo();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

by the way i think i get what mean linkage

linkage we can use in flash CS3

but i use CS4 , thats why i dont see it.. here just properties..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2010 Apr 19, 2010

import the Font class:

import flash.text.Font;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

imported, but still in .swf i see strange number with space on top, and number without footer, like on picture what i attached

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

also changed font, but problem the same

aa.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2010 Apr 19, 2010

that's not a font embedding problem.

make sure multiline is disabled.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

i don't use any special properties for this dynamic font

i just create dynamic font with instance name..

pic with properties:

eee.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2010 Apr 19, 2010

yraaaaaa

find answer:)

there was specing..:) strange i never used it..:)

ok, thank you for everyone for help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2010 Apr 20, 2010

you're welcome.

p.s.  (-53pt is extreme)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 20, 2010 Apr 20, 2010

i dont know what put it there:) its not me

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2010 Apr 20, 2010
LATEST

LOL.

denial is rampant in these forums!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines