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