我正在尝试使用GDS Tide框架。我的基本代码就是这个:
<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"
preinitialize="Tide.getInstance().initApplication()">
<fx:Script>
<![CDATA[
import controllers.TestController;
import events.TestEvent;
import models.TestModel;
import models.interfaces.ITestModel;
import mx.events.FlexEvent;
import org.granite.tide.Tide;
[Bindable][Inject]
public var testModel:ITestModel;
Tide.getInstance().addComponents([TestController, TestModel]);
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:Label text="{testModel.ab}" />
<s:Button click="dispatchEvent(new TestEvent());" label="test !" />
我可以编译并运行我的代码但是当我启动我的应用程序时,我看到空白的窗口,我的按钮或我的标签没有出现。没有错误被解雇。
当我将代码更改为此代码时:
<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"
preinitialize="Tide.getInstance().initApplication()" creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import controllers.TestController;
import events.TestEvent;
import models.TestModel;
import models.interfaces.ITestModel;
import mx.events.FlexEvent;
import org.granite.tide.Tide;
[Bindable][Inject]
public var testModel:ITestModel;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
Tide.getInstance().addComponents([TestController, TestModel]);
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:Label text="{testModel.ab}" />
<s:Button click="dispatchEvent(new TestEvent());" label="test !" />
它有效我看到标签和按钮但我的标签没有正确初始化,因为我的控制器和模型已添加到mx.events.FlexEvent.CREATION_COMPLETE
事件。
我用第一种(和推荐的)方法做错了什么?