2009-06-24 99 views
0

因为我想避免重复的代码,并且我使用了很多文本格式,所以我在Flex Builder中创建了一个CustomTextFormat类。Flash/Flex错误1067:无法创建自定义的TextFormat对象?

另一类,称为CustomInputBox.as使用这个对象来创建格式:

package 
{ 
    import flash.display.Sprite; 
    import flash.text.TextField; 
    import flash.text.TextFieldType; 

    public class CustomInputBox extends Sprite 
    { 
     public function CustomInputBox(xLoc:int, yLoc:int, width:uint, height:uint, password:Boolean = false, text:String = "", font:String = "Arial", fontColor:uint = 0x000000, fontSize:uint = 18, fontBold:Boolean = false) 
     { 
      var inputBox:TextField = new TextField(); 
      inputBox.type = TextFieldType.INPUT; 
      inputBox.mouseEnabled = true; 
      inputBox.selectable = true; 
      inputBox.multiline = false; 
      inputBox.x = xLoc; 
      inputBox.y = yLoc; 
      inputBox.width = width; 
      inputBox.height = height; 
      inputBox.displayAsPassword = password; 
      var format:CustomTextFormat = new CustomTextFormat(); 
      inputBox.defaultTextFormat = format; 
      inputBox.text = text; 
      addChild(inputBox); 
     } 
    } 
} 

CustomTextFormat的代码如下:

package 
{ 
    import flash.display.Sprite; 
    import flash.text.TextFormat; 
    import flash.text.TextFormatAlign; 

    public class CustomTextFormat extends Sprite 
    { 
     public function CustomTextFormat(font:String = "Arial", fontColor:uint = 0x000000, fontSize:uint = 18, fontBold:Boolean = false, fontAlign:String = TextFormatAlign.LEFT) 
     { 
      var format:TextFormat = new TextFormat(); 
      format.font = font; 
      format.color = fontColor; 
      format.size = fontSize; 
      format.bold = fontBold; 
      format.align = fontAlign; 
     } 
    } 
} 

现在,我收到提示1067在CustomInputBox.as文件中,不幸的是(将flex错误设置为英语的任何方式?):

1067:在een niet-gerelateerd类型中使用CustomTextFormat类型flash.text:TextFormat。 CustomInputBox.as

这很难翻译,但希望错误号码和代码足以识别我的问题。我是新来的Flash,并搜索,但无法找出我做错了什么。

在此先感谢。

回答

1

这里有点古怪。如果您想将自订格式是这样的:

var format:CustomTextFormat = new CustomTextFormat(); 
inputBox.defaultTextFormat = format; 

然后CustomTextFormat需要延续的TextFormat,并在CustomTextFormat的构造函数的代码应该修改继承TF性能。另外,如果你想离开CustomTextFormat扩展雪碧,那么你需要改变CustomTextFormat的“格式”属性是公共属性,改变你的分配是这样的:

var customFormat:CustomTextFormat = new CustomTextFormat(); 
inputBox.defaultTextFormat = customFormat.format; 

这是否有意义?现在你试图将输入的默认文本格式设置为扩展Sprite的类对象。而inputBox不知道任何关于CustomTextFormat的内部“格式”属性,这是私人的和临时的。

(顺便说一句,这些都不能准确地解释你所得到的错误信息,但根据我的经验,Flash编译器错误到确实告诉你什么是错误......他们倾向于声称你正在使用类非法的,当你所做的只是省略分号。我倾向于不相信错误信息太多。)

+0

非常感谢。这会让我更进一步。 我的问题是我真的不知道扩展是什么,我只是默认使用Sprite。我真的需要找到一个... – Tom 2009-06-24 09:58:00