0
<?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="640" minHeight="480">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import flash.display.Shape;
import flash.display.Sprite;
import mx.core.UIComponent;
import spark.core.SpriteVisualElement;
private var rectangle:Sprite = new Sprite();
private var insterter:UIComponent = new UIComponent();
private var theme:SpriteVisualElement = new SpriteVisualElement();
private function main():void
{
rectangle.graphics.lineStyle(1,0x0000FF,1.0);
rectangle.graphics.drawRect(0,0,200,50);
theme.addChild(rectangle);
this.addElement(theme); //tried canvas.addElement
const WIDTH:int = 20;
const HEIGHT:int = 20;
/*var grid:Array = new Array();
for(var y:int = 0; y < HEIGHT; y++) {
var row:Array = new Array();
for (var x:int = 0; x < WIDTH; x++) {
row.push(/*random object*//*);
}
/ grid.push(row);
}*/
}
]]>
</fx:Script>
<!--<spark:Canvas id="canvas" x="34" y="10" width="90%" height="90%" textAlign="center">
</mx:Canvas>-->
</s:Application>
基本上這是行不通的。我用這個問題來改善 - 仍然沒有。 Why doesnt this Flex App draw a simple rectangle?如何在flex 4.5.1中繪製矩形?
仍然無法正常工作。我使用的Flex項目不是純粹的動作。 – Smoke
確保您通過在Application MXML標記中添加creationComplete =「main()」屬性來調用主函數。我寫的代碼當然可以工作,如果放在一個被調用的函數中。 – LoremIpsum
ooooops .....該死的。抱歉。是的,現在完美工作。我忘了fx需要creationComplete =「main()」與mx相同。 – Smoke