国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

11.7.用HistoryManagement整合States視圖

2024-04-27 13:52:12
字體:
供稿:網(wǎng)友
11.7.1. 問題
我想用Flex 框架的HistoryManagement 機(jī)制整合states。
11.7.2. 解決辦法
創(chuàng)建擴(kuò)展自IHistoryManagerClient 接口的應(yīng)用程序或組件。使用HistoryManagement 注冊應(yīng)用程序,當(dāng)state 改變時使用HistoryManager.save 方法保存當(dāng)前state。
11.7.3. 討論
IHistoryManager client 定義了以下方法:
loadState(state:Object):void
加載此對象的狀態(tài)
saveState():Object
保存此對象的狀態(tài)
toString():String
將此對象轉(zhuǎn)換為唯一的字符串

這些方法允許組件能正確的保存State 的任何信息,在需要時進(jìn)行還原。loadState 方法從存儲的URL 載入State 信息:
+展開
-ActionScript
public function saveState():Object {
trace(" save state ");
var state:Object = {};
state.lastSearch = lastSearch;
state.currentState = currentState;
return state;
}

loadState 方法接受和讀取從HistoryManager 中傳過來的object 中的State,并設(shè)置組件的currentState:
+展開
-ActionScript
public function loadState(state:Object):void {
if (state) {
trace(" last search "+state.lastSearch);
lastSearch = searchInput.text = state.lastSearch;
currentState = state.currentState;
}
}

完整代碼如下:
+展開
-XML
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.managers.IHistoryManagerClient"
creationComplete=" HistoryManager.register(this)"
currentState="search">

<mx:Script>
<![CDATA[
import mx.managers.HistoryManager;
public function loadState(state:Object):void {
if (state!=null) {
trace(" last search "+state.lastSearch);
lastSearch = searchInput.text = state.lastSearch;
currentState = state.currentState;
}
}
// Save the current state and the searchString value.
public function saveState():Object {
trace(" save state ");
var state:Object = {};
state.lastSearch = lastSearch;
state.currentState = currentState;
return state;
}
// The search string value.
[Bindable]
public var lastSearch:String;
public function search():void {
lastSearch = searchInput.text;
currentState = "display";
HistoryManager.save();
}
public function reset():void {
trace(" reset ");
currentState = 'search';
searchInput.text = "";
lastSearch = "";
HistoryManager.save();
}
]]>
</mx:Script>
<mx:states>
<mx:State name="display">
<mx:SetProperty target="{panel}name="title"
value="Results"/>

<mx:AddChild relativeTo="{panel}">
<mx:VBox id="results">
<mx:Text text="Getting Results"/>
<mx:Button label="Resetclick="reset()"/>
</mx:VBox>
</mx:AddChild>
</mx:State>
<mx:State name="search">
<mx:SetProperty target="{panel}name="title"
value="Search"/>

<mx:AddChild relativeTo="{panel}">
<mx:HBox id="searchFieldsdefaultButton="{btn}">
<mx:TextInput id="searchInput" />
<mx:Button id="btnlabel="Find"
click="search();" />

</mx:HBox>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Panel id="paneltitle="ResultsresizeEffect="Resize">
</mx:Panel>
</mx:Application>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南通市| 雅江县| 汉源县| 历史| 泸溪县| 陕西省| 内乡县| 濮阳市| 石景山区| 安西县| 资阳市| 乌苏市| 馆陶县| 安图县| 西贡区| 宽甸| 安康市| 梓潼县| 兴安县| 黑龙江省| 定边县| 岢岚县| 丹东市| 清新县| 灵寿县| 藁城市| 阿克陶县| 镶黄旗| 定陶县| 孝感市| 灌阳县| 尉氏县| 出国| 宣恩县| 敦化市| 香格里拉县| 岳西县| 静宁县| 曲沃县| 永昌县| 璧山县|