0

皆さん、ハッピー火曜日:)

いくつかのサブクラスで同じフォントを繰り返し使用していることに気付いたので、それらすべてを処理するフォント クラスを作成することにしました。

とにかく、 Fonts クラスで作成された TextFormatsを他の Classes にきれいに取り込む方法について頭を悩ませています。これを正しい方法で行っているとは思いませんが、現在、次のエラー メッセージが表示されます。

footFont = null TypeError: エラー #2007: パラメータの形式は null 以外である必要があります。

フレーム クラスに avant97 TextFormat を渡してフッター テキストのスタイルを設定したい

以下は私のフォントクラスです。

package src.model 
{
    import flash.text.*;

    public class Fonts
    {
        public static var data:Object = {};
        public static var avant97 = new TextFormat(); // Footer copy
        public static var avantFF = new TextFormat(); // Navigation Copy
        public static var avant0s = new TextFormat(); // Thumbnail Titles

        avant97.font  = (new AvantGrande() as Font).fontName;
        avant97.size  = 16;
        avant97.color = 0x979797;
        avant97.align = TextFormatAlign.CENTER;

        avantFF.font  = (new AvantGrande() as Font).fontName;
        avantFF.size  = 16;
        avantFF.color = 0xFFFFFF;
        avantFF.align = TextFormatAlign.CENTER;

        avant00.font  = (new AvantGrande() as Font).fontName;
        avant00.size  = 16;
        avant00.bold  = true;
        avant00.color = 0x000000;
        avant00.align = TextFormatAlign.LEFT;
    }

}

代替テキスト


これは、avant97 を TextField にアタッチしようとしている Frame クラスです。

package src.display{

import flash.text.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.events.Event;

// ☼ --- Imported Classes
import src.events.CustomEvent;
import src.model.Fonts;

public class Frame extends Sprite {

    private var footer:Sprite = new Sprite();
    private var fnt:Fonts; // <- var for Fonts Class
    private var footFont:TextFormat; // var to hold avant97

    // ☼ --- Constructor
    public function Frame():void {
        this.addEventListener(Event.ADDED_TO_STAGE, init);
    }

    // ☼ --- Init
    public function init():void {

        fnt = new Fonts(); // init the Fonts class
        //fnt.data.avant97 = footFont; // trying to get avant97
        Fonts.data.avant97 = footFont;  // Changed per 1st answer
        trace("footFont = "+footFont); // Fail

        footer.graphics.beginFill(0x000);
        footer.graphics.drawRect(0,0,800,56);
        footer.graphics.endFill();
        footer.y = stage.stageHeight - footer.height;

        var footText:TextField = new TextField();
        footText.defaultTextFormat = footFont; // Fail x 2!
        footText.antiAliasType = flash.text.AntiAliasType.NORMAL;
        footText.selectable = false;
        footText.mouseEnabled = false;
        footText.wordWrap = true;
        footText.width = 800;
        footText.height = 30;
        footText.text = footCopy;

        // ☼ --- Place Footer & Copy
        footer.addChild(footText);

        addChild(footer);

        trace("Frame added --- √"+"\r");
        this.removeEventListener(Event.ADDED_TO_STAGE, init);
    }

}

}

基本的に、私は [ここから static var データ オブジェクトのアイデア] [2] を得ましたが、彼の例は実際のデータに対してのみ機能するのでしょうか? TextFormats ではありませんか?

これは私がもう一度得ているエラーです: footFont = null TypeError: エラー #2007: パラメータ形式は非 null でなければなりません。

4

2 に答える 2

2

テキスト形式を他のコードから分離したいだけの場合は、Fonts クラスを「静的」(インスタンス化してはならない) と考える必要があります。Fonts クラスのすべてのメソッドとプロパティは、Fonts.method() Fonts.property のように参照されます。

private footFont : TextFormat = Fonts.avant97;

プロパティを編集しない限り、avant97 のコピーを作成する必要はないことに注意してください。footFont の代わりに Fonts.avant97 を使用できます。

于 2009-11-17T18:55:42.913 に答える
1

静的変数であるため、fnt.data を Fonts.data に変更します。

于 2009-11-17T18:19:47.533 に答える