我想为一个最小的程序,可以画一条线,在一个新的Flex项目(使用Flash Builder 4.6):为什么这个ActionScript 3代码不能画出一条线?
但是,当它在Web浏览器(Chrome或Firefox),并且按钮运行myButton
被点击,没有线被绘制 - 是否有人知道如何使它工作,以及如何使它可以绘制而不需要点击按钮?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
public function drawLine():void
{
var canvas:Shape = new Shape();
canvas.graphics.lineStyle(3, 0xff);
canvas.graphics.moveTo (0,0);
canvas.graphics.lineTo(300,300);
this.addChild(canvas);
}
]]>
</fx:Script>
<s:Button label="myButton" click="drawLine()" />
</s:Application>
你可能会尝试Spark [SpriteVisualElement](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/core/SpriteVisualElement.html)或[Graphic](http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/spark/primitives/Graphic.html)而不是Shape, –
正在使用Shape可能吗?在O'Reilly的Essential ActionScript 3.0中,p。 630,它使用形状,但只是它没有完整的程序列表 –
那么,你的形状没有指定任何高度或宽度。我不相信形状有代码来自动调整大小。 – JeffryHouser