我想爲一個最小的程序,可以畫一條線,在一個新的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