国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 玛多县| 灌云县| 曲阳县| 醴陵市| 辛集市| 平果县| 乐清市| 东方市| 兴仁县| 二手房| 城口县| 安塞县| 玛纳斯县| 读书| 靖西县| 阿鲁科尔沁旗| 突泉县| 大城县| 石台县| 屏山县| 乌拉特后旗| 曲麻莱县| 勃利县| 梅州市| 河东区| 依安县| 龙南县| 宁陵县| 普兰店市| 兰西县| 平安县| 江孜县| 岳阳县| 潜江市| 宝应县| 得荣县| 海兴县| 连南| 朔州市| 海兴县| 比如县|