剛開始學習Flex。但是我對基本代碼感到興奮。我正在嘗試檢查如何通過操作腳本將組件(例如按鈕)添加到應用程序容器。但是我無法看到輸出中的按鈕。下面是我的代碼,使用動作腳本動態添加組件
<?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"
creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import spark.components.Button;
import spark.layouts.BasicLayout;
private function init():void{
var bl:BasicLayout = new BasicLayout();
var app:Application = new Application();
var button1:Button = new Button();
var button2:Button = new Button();
button1.label ="Button one";
button1.x = 100;
button2.label = "Two";
button2.x = 30;
layout = bl;
addChild(button1);
addChild(button2);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
什麼是錯誤的,我在這裏做什麼?
感謝
也許你應該告訴我們什麼不起作用? –