2011-12-28 53 views
0

下面是填充菜單的代碼。除了一個關鍵部分,一切似乎都很好,沒有錯誤。我megaPages陣列具有的值["HOME","BABIES","BRIDALS","MISC","WEDDINGS","ABOUT"],但(這是由megaPages生產),其顯示在屏幕上的實際文本是這樣的:如何防止AS3中的此任意文本截斷

strange menu problems

正如你可以看到,一些文字是任意被截斷。我已經追蹤了文本字符串,因爲它們在菜單構建的各個階段通過各種函數來傳遞,並且它們總是正確的,但不知何故,當每個DisplayObject在屏幕上顯示時,字母都會被忽略(注意儘管「HOME」 abd'ABOUT'很好)。我甚至不知道從哪裏開始解決這個問題。

function buildMenu() { 
     var itemMCs = new Array(); 

     for (var i = 0; i < megaPages.length; i++) { 
      megaPages[i] = megaPages[i].toUpperCase(); 
      trace(megaPages[i]); // at each iteration, traces as follows "HOME","BABIES","BRIDALS","MISC","WEDDINGS","ABOUT" 
      var textMC = createText(megaPages[i]); 

      var itemMC = new MovieClip(); 
      if (i!=0) { 
       var newLink = new PlateLink(); 
       newLink.y = 0; 
       itemMC.addChild(newLink); 
      } 


      var newPlate = new Plate(); 
      if (i==0) { 
       newPlate.y = 0; 
      } else { 
       newPlate.y = newLink.height - 2; 
      } 
      newPlate.x = 0; 
      newPlate.width = textMC.width + (plateMargin*2); 
      itemMC.addChild(newPlate); 

      if (i!=0) { 
       newLink.x = (newPlate.width/2) - (newLink.width/2); 
      } 

      textMC.x = plateMargin; 
      textMC.y = newPlate.y + .5; 
      itemMC.addChild(textMC); 

      itemMCs.push(itemMC); 

      itemMC.x = (homeplateref.x + (homeplateref.width/2)) - (itemMC.width/2); 
      if (i==0) { 
       itemMC.y = homeplateref.y; 
      } else { 
       itemMC.y = itemMCs[i-1].y + (itemMCs[i-1].height - 6); 
      } 
      menuRef.addChild(itemMC); 

     } 

    } 

    function createText(menuTitle) { 

     trace(menuTitle); 

     var textContainer : MovieClip = new MovieClip(); 

     var myFont = new Font1(); 

     var backText = instantText(menuTitle, 0x000000); 

     backText.x = 1; 
     backText.y = 1; 

     var frontText = instantText(menuTitle, 0xFFFFFF); 

     frontText.x = 0; 
     frontText.y = 0; 

     textContainer.addChild(backText); 
     textContainer.addChild(frontText); 
     return textContainer; 
    } 

    function instantText(textContent, color) { 

     trace(textContent); // again, traces the right text each time it is fired 

     var myFont = new Font1(); 
     var myFormat:TextFormat = new TextFormat(); 
     myFormat.size = 18; 
     myFormat.align = TextFormatAlign.CENTER; 
     myFormat.font = myFont.fontName; 

     var myText:TextField = new TextField(); 
     myText.defaultTextFormat = myFormat; 
     myText.embedFonts = true; 
     myText.antiAliasType = AntiAliasType.ADVANCED; 
     myText.text = textContent; 
     myText.textColor = color; 
     myText.autoSize = TextFieldAutoSize.LEFT;   
     trace(myText.text); 

     return myText; 
    } 
+1

看起來像你需要嵌入字體 – Ronnie 2011-12-28 17:52:05

+0

什麼是'PlateLink'和'Plate'? – www0z0k 2011-12-28 18:58:41

+0

Plate和PlateLink是灰色正方形的實例,並且鏈接文本的每一位 – 2011-12-28 19:08:40

回答

2

您需要爲您使用的字體嵌入所有必需的字符。

對於在Flash中創建文本框:
選擇文本字段,並在屬性面板中打的「嵌入」按鈕。

動態創建文本框:
當您設置字體(在你的情況Font1)出口,確保包含所有你需要的字符。

您可以選擇嵌入所有大寫字符,或者只需鍵入您需要的那些特定菜單項。

+0

我不確定我明白你在說什麼。這些文本字段通過AS3生成,並且我的字體作爲類Font1()導出。在Flash Authoring程序中有什麼文本字段,那麼對我來說呢?嵌入到底是爲我做什麼的? – 2011-12-28 19:20:36

+0

對不起,我以爲你在用Flash創建文本框。我會更新我的答案。 – Cadin 2011-12-28 20:34:08

+0

是的,就是這樣,我只是從Font1的屬性中選擇'包含所有字符範圍'。哇,我couyld已經花了6個多小時,並且一直無所事事,謝謝! – 2011-12-28 20:39:33