0

Flexアプリケーションには、「truncateToFit」プロパティがtrueに設定されているラベルがいくつかあります。問題は、切り捨てられたテキストの最後に「...」を表示する代わりに、nullを表示することです。

つまり、私のラベルのテキストが「Hello Stackoverflow!」だった場合です。私のラベルは次のようになると思います。

「こんにちはStackov...」

代わりに表示されます

「こんにちはStackovnull」

どんな助けでも役に立ちます!

切り捨てがどのように見えるかの例

編集:-サンプルコード:

<mx:HBox width="200" ... >
   <mx:Label maxWidth="150" truncateToFit="true" text="Really long text.Really long text.Really long text.Really long text.Really long text" />
</mx:HBox>
4

6 に答える 6

2

ハハ!私は解決策を見つけました。申し訳ありませんが-おそらく私の情報不足が原因で、mのデバッグが困難になりました:(

したがって、とにかく-ローカライズされた言語データなどを取得するためにアプリケーションがロードした外部resourceModule swfがあったことがわかりました-このファイルには、切り捨てのために表示するテキストに関するデータが含まれていませんでした(つまり'...')そのため、代わりに「null」が表示されました。そのデータをResourceswfに追加しましたが、すべて期待どおりに機能しています。

みんなを助けてくれてありがとう。;)

于 2009-04-21T13:37:30.430 に答える
1

問題は、コンパイル済みのローカリゼーション ファイルにデフォルトの Flex リソース バンドルの 1 つが含まれていないことです。詳細な説明と修正については、こちらを参照してください: http://deniszgonjanin.posterous.com/flex-truncation-null-error-fix

于 2010-09-02T21:38:54.867 に答える
0

複数のロケールで作業する場合は、必ず「en_US」を localeChain に追加してください。例: resourceManager.localeChain = ['pt_BR', 'en_US'];

解決策が見つかりました: http://blog.flexexamples.com/2008/01/26/truncating-text-in-the-flex-label-control-using-the-truncatetofit-property/

レアンドロの投稿を探してください

于 2009-11-05T03:22:16.943 に答える
0

そこで、独自のフォントを埋め込んでみましたが、特に問題なく切り捨てられます。フォントをどのように埋め込んでいるのかわかりませんが、この方法はうまくいきました。まったく異なることをしている場合は、投稿で指定してください。

// Cannot name the font as one that already exists!
[Embed(source="Anonymous.ttf", fontFamily="myAnon")]
private var fontA : Class;

[Embed(source="HGRSGU.TTC", fontFamily="myFont")]
private var fontB : Class;

//...I have some code here that switches the font
var obj : Object = truncateMe.getStyle("fontFamily");
if (obj == "myAnon")
  truncateMe.setStyle("fontFamily", "myFont");
else
  truncateMe.setStyle("fontFamily", "myAnon");

<!-- My Label -->
<mx:Label maxWidth="150" truncateToFit="true" id="truncateMe"
    text="Something really long goes here" fontFamily="myFont" fontSize="20"/>
于 2009-04-18T05:30:25.120 に答える
0

サンプルコードを試してみたところ、うまくいきました。あなたはそれが他のものではないことを確信していますか?

于 2009-04-17T04:50:32.010 に答える
0

私は今日 (3 時間) この問題で大喧嘩をしました。とにかく、上記のヒントのどれも私の問題を解決しませんでした。私はそれをすべて試しました。クラスを拡張する独自のクラスを作成することになりましたmx.controls.Label。実装は以下。プロジェクトで自由に使用してください。これを使用する場合は、mxml で truncateToFit を無効にする必要があることに注意してください。それ以外の場合、「null」文字列がテキストに追加され、切り捨ては行われません。

コード:

package com.feijk.UI {
    import mx.controls.Label;


    /**
     * An extension for mx.controls.Label to truncate the text and show
     * a tooltip with the full-length content. This sub-class is meant to be
     * used when the regular truncateToFit does result in a "null" appendix
     * on the string instead of the "...". In order for this to work, I used
     * the following parameters in my mxml: 
     * 
     *  - truncateToFit = false
     *  - maxWidth = set
     *  - width = set
     * 
     * 
     * @author Tomi Niittumäki // Feijk Industries 2010
     * @NOTE: Feel free to use! :)
     */
    public class FLabel extends Label{

        // define the truncation indicator eg. ...(more) etc.
        private const TRUNCATION_INDICATOR:String = new String("...");

        /**
         * Constructor
         */
        public function FLabel(){
            super();
        }

        /**
         * The overriding method, which forces the textField to truncate
         * its content with the method truncateToFit(truncationIndicator:String)
         * and then supers the tooltip to be the original full-length text.
         */
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            //trace("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: "+textField.text);
            textField.truncateToFit(TRUNCATION_INDICATOR);
            super.toolTip = text;
        }

    }
}
于 2010-07-06T15:18:53.477 に答える