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
Apache flex 在图形中用Flex呈现文本_Apache Flex_Flash_Actionscript - Fatal编程技术网

Apache flex 在图形中用Flex呈现文本

Apache flex 在图形中用Flex呈现文本,apache-flex,flash,actionscript,Apache Flex,Flash,Actionscript,我对Flex(和Flash)还不熟悉,现在只是随便玩玩。我使用画布上的绘图方法将其涂成蓝色,并希望绘制文本,但是,代码中的某个地方出现了错误 <?xml version="1.0" ?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom=

我对Flex(和Flash)还不熟悉,现在只是随便玩玩。我使用画布上的绘图方法将其涂成蓝色,并希望绘制文本,但是,代码中的某个地方出现了错误

<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" enterFrame="enterFrame(event)" applicationComplete="addtext(event)">
    <mx:VBox width="640" height="480">
        <mx:Label id="debug" text="No debug yet." />
        <mx:Button id="myButton" label="Hello World" />
        <mx:Button id="myOtherButton" label="Foo Bar Baz" />
        <mx:Canvas id="myCanvas" width="100%" height="100%" />
    </mx:VBox>
    <mx:Script>
    <![CDATA[
    import flash.text.engine.*;
    import mx.controls.*;

    public function addtext(event:Event):void
    {
        Alert.show("foo!");
        var str:String = "Hello World.";
        var format:ElementFormat = new ElementFormat();
        var textElement:TextElement = new TextElement(str, format);
        var textBlock:TextBlock = new TextBlock();
        textBlock.content = textElement;
        var textLine:TextLine = textBlock.createTextLine(null, 300);
        textLine.x = 30;
        textLine.y = 200;
        Alert.show("baz!");
        this.addChild(textLine); // Execution appears to cease here.
        Alert.show("bar!");
    }

    public function enterFrame(event:Event):void
    {
        myCanvas.graphics.clear();
        myCanvas.graphics.beginFill(0x66666FF);
        myCanvas.graphics.drawRect(0, 0, myCanvas.width, myCanvas.height);
        myCanvas.graphics.endFill();
    }
    ]]>
    </mx:Script>
</mx:Application>


警报到达“baz!”而不是“bar!”,因此错误就在那里的某个地方。另外,我已经在Firefox和
fdb
中运行了这个程序,但是
fdb
没有输出任何东西-它只是启动了一个Flash播放器。如何调试Flash的起点是Flash和flex之间有点模糊的混合。 第一:我建议,如果您希望画布是蓝色的,您可以使用:

<mx:canvas backgroundColor="0x66666FF" width="100%" height="100%" />

其次,文本布局框架(通常是TLF)是一个我建议您跳过的主题,直到您更熟悉flex和flash为止

出现的错误是因为TextLine未实现IUIComponent,因此无法添加到Flex容器中

如果你想使用TLF,你需要在你的应用程序中添加一个能够处理它的spark组件,例如s:RichText或s:TextArea


快乐编码

您使用更复杂的FTE类而不仅仅是创建/添加flex标签组件,这有什么原因吗?我的下一个问题是“为什么
addChild
不使用
IUIComponent
”,但这似乎可以解释它。我有一个使用
Label
的例子,我看了一下
RichText
的文档。谢谢