문제

I'm building an application using Flash CS6 and AS3, where there will be loads of texts. So I want to create only one text format object for all of them. I am using this code:

public class MyClass extends MovieClip {

    public var formatTitle = new TextFormat();
    formatTitle.size = 50; <-- ERROR HERE

    public function MyClass(){
        buildHome();
    }

    public function buildHome(){
        var title:TextField = new TextField();
        title.text = "HOME";
        title.defaultTextFormat = formatTitle;
        addChild(title);
    }

}

But I'm getting the error: Access of undefined property formatTitle where it says formatTitle.size = 50. But it's here above it! What am I missing?

Thanks in advance.

도움이 되었습니까?

해결책

You need to move formatTitle.size = 50; at the beginning of the constructor. You can't have code like this outside of a method.

public function MyClass(){
    formatTitle.size = 50;
    buildHome();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top