国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 花莲县| 台南县| 青河县| 灵宝市| 大理市| 上思县| 鄂温| 红河县| 乌审旗| 安丘市| 花垣县| 当雄县| 黄梅县| 西林县| 突泉县| 平利县| 新晃| 郁南县| 民和| 嘉善县| 邵阳市| 巧家县| 麻城市| 延长县| 昂仁县| 宽甸| 延安市| 托克逊县| 云林县| 波密县| 衡阳县| 建始县| 衡南县| 仙居县| 曲周县| 那坡县| 无棣县| 贡觉县| 井研县| 定边县| 金堂县|