Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Flex 4.6:在textInput上设置textFormat_Actionscript 3_Apache Flex_Adobe_Flash Builder_Flex4.6 - Fatal编程技术网

Actionscript 3 Flex 4.6:在textInput上设置textFormat

Actionscript 3 Flex 4.6:在textInput上设置textFormat,actionscript-3,apache-flex,adobe,flash-builder,flex4.6,Actionscript 3,Apache Flex,Adobe,Flash Builder,Flex4.6,我正在尝试在textInput组件上设置textFormat。像这样: var testText:TextInput = new TextInput(); testText.text = "TESTING"; addChild(testText); var tf:TextFormat = new TextFormat(); tf.leftMargin = 50; tf.size = 20; tf.color = 0xFF0000; testText.setStyle("textFormat",

我正在尝试在textInput组件上设置textFormat。像这样:

var testText:TextInput = new TextInput();
testText.text = "TESTING";
addChild(testText);

var tf:TextFormat = new TextFormat();
tf.leftMargin = 50;
tf.size = 20;
tf.color = 0xFF0000;
testText.setStyle("textFormat", tf);

根据(以及网络上的许多例子)的说法,这应该是可能的。然而,文本从未应用过它的样式。我尝试了spark和MX TextInput(甚至还有TextArea),但结果总是一样的。我错过什么了吗?或者这不再是受支持的操作了?

注意有3个
TextInput

  • --这是Flash Professional提供的,在Flex应用程序中不是很有用。它是一个有“textFormat”样式的(Flex-one没有这种样式)

  • --来自Flex 3 SDK的旧Flex组件

  • --Flex 4 SDK中组件的Spark版本

最后两个没有“textFormat”样式,因此上面的代码无法工作

您可以使用Flex组件支持的单个样式,而不是尝试使用“textFormat”样式。。。这些在Actionscript中应用有些繁琐,但在MXML中很容易。我链接到的文档有一个“样式”部分,您可以在其中查看可应用于文本的样式

AS3:

MXML:



是的,那是过去的日子。但是现在,对于皮肤、CSS和TLF,您可以进行的高速样式设计几乎没有限制。最简单的方法是定义一个CSS样式并使用styleName=“myStyle”。您还可以使用样式表(内联或外部文件)来减少重复。选项根据您使用的是mx还是spark而有所不同。这是spark的信息:+1 Lee完全同意。在我对这个问题的评论中使用CSS。@JasonReeves同意,我省略了CSS选项。但OP面临的真正问题是试图将Flash Pro的TextInput样式应用于Flex TextInput。无论采用哪种方式应用样式,这都是行不通的。请注意,OP提供的文档链接不是Flex的文档,而是Flash CS4:)@SunilD的文档。是的,你的答案是正确的,为什么它不起作用(这是尼克问的)。。只是同意Lee的观点,CSS是Nick尝试使用的内联样式的更好的替代品。这就解释了这一点。我看到的只是Actionscript,我想我在文档中找到了正确的位置。谢谢大家!
var t:TextInput = new TextInput();
t.setStyle("fontSize", 18);
t.setStyle("color", 0xFF0000);
<s:TextInput fontSize="18" color="0xFF0000" />