国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 嵊泗县| 定西市| 漠河县| 红原县| 鄂托克前旗| 高雄市| 陇南市| 英德市| 漳浦县| 德昌县| 洛川县| 莫力| 年辖:市辖区| 珲春市| 阳城县| 班戈县| 安徽省| 汉阴县| 新密市| 康马县| 静海县| 泰安市| 祥云县| 兴海县| 无极县| 淮北市| 沭阳县| 平度市| 石城县| 潮州市| 浙江省| 兴仁县| 阿勒泰市| 神木县| 白山市| 塔河县| 扎囊县| 历史| 化隆| 山东省| 嘉荫县|