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

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

17.8.記住用戶輸入文本框的內(nèi)容

2024-04-27 13:52:24
字體:
供稿:網(wǎng)友
17.8.1. 問題
我想要再用戶離開應(yīng)用程序的時(shí)候,記住用戶輸入的TextInput 的字段。
17.8.2. 解決辦法
創(chuàng)建一個TextInput 組建的子類,當(dāng)用戶輸入的時(shí)候來使用本地共享對象存貯用戶輸入的文本值。
17.8.3. 討論
為了方便,現(xiàn)代瀏覽器都提供了記住用戶上次在公共表單區(qū)域輸入值和登陸提示,這些值在用戶再次訪問的時(shí)候不用再次輸入。默認(rèn)情況,F(xiàn)lex 應(yīng)用程序沒有繼承這個非常有用的行為,但是你可以很簡單的通過使用本章的例子中的自定義組件來實(shí)現(xiàn)。

這個組件繼承于TextInput 類,增加了一個靜態(tài)方法到TextInput 的API,被設(shè)計(jì)了用來記住最后一次的值. persistenceId 屬性是存貯ID 用來指定這個組件的實(shí)例。靜態(tài)方法clearStoredValues()讓你可以全局晴空所有之前存貯的值。代碼如下:
+展開
-ActionScript
package custom
{
import flash.events.Event;
import flash.net.SharedObject;
import mx.controls.TextInput;
public class PersistentTextInput extends TextInput
{
/**
* The ID this component will use to save and later look up its
* associated value.
*/

public var persistenceId:String = null;
/**
* The SharedObject name to use for storing values.
*/

private static const LOCAL_STORAGE_NAME:String =
"persistentTextInputStorage";
/**
* Clears previously stored values for all PersistentTextInput instances.
*/

public static function clearStoredValues() :void
{
var so:SharedObject = SharedObject.getLocal(LOCAL_STORAGE_NAME);
so.clear();
}
/**
* Handles initialization of this component.
*/

override public function initialize() :void
{
super.initialize();
addEventListener(Event.CHANGE, handleChange);
restoreSavedValue();
}
/**
* Event handler function for CHANGE events from this instance.
*/

protected function handleChange(event:Event) :void
{
saveCurrentValue();
}
/**
* Restores the previously saved value associated with the
* persistenceID of with this instance.
*/

protected function restoreSavedValue() :void
{
if (persistenceId != null)
{
var so:SharedObject =
SharedObject.getLocal(LOCAL_STORAGE_NAME);
var value:String = so.data[persistenceId];
if (value != null)
{
text = value;
}
}
}
/**
* Saves the text value of this instance. Associates the value with
* the persistenceId of this instance.
*/

protected function saveCurrentValue() :void
{
if (persistenceId != null)
{
var so:SharedObject =
SharedObject.getLocal(LOCAL_STORAGE_NAME);
so.data[persistenceId] = text;
so.flush();
}
}
}
}

如下應(yīng)用程序示范了如何使用這個新組件。測試這些功能,載入應(yīng)用程序,輸入一些文字,然后關(guān)閉應(yīng)用程序。當(dāng)你再次打開應(yīng)用程序的時(shí)候,你會看到之前輸入的一些字段會有之前你輸入的值。
+展開
-XML
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxmlxmlns:custom="custom.*layout="vertical">
<mx:Script>
<![CDATA[
import custom.PersistentTextInput;
public function clearValues() :void
{
PersistentTextInput.clearStoredValues();
message.text = "A page refresh will reveal that the
values have not persisted.";
}

]]>
</mx:Script>
<custom:PersistentTextInput id="firstNameInput"
persistenceId="firstName" />

<custom:PersistentTextInput id="lastNameInput"
persistenceId="lastName" />

<mx:Button label="Clear Persistent Values"
click="clearValues()" />

<mx:Label id="message" />
</mx:Application>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 揭西县| 桃江县| 连州市| 寿宁县| 吉木萨尔县| 乌苏市| 苍山县| 蚌埠市| 眉山市| 宁强县| 高要市| 平湖市| 衡山县| 肇庆市| 铁岭市| 龙游县| 平塘县| 阆中市| 同心县| 兴业县| 丹江口市| 新沂市| 平利县| 庄浪县| 明光市| 皋兰县| 乌兰县| 古交市| 黄浦区| 全南县| 宁都县| 阿合奇县| 高台县| 湘阴县| 察哈| 芜湖市| 漠河县| 开原市| 明溪县| 鹿邑县| 平南县|