国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 大邑县| 咸丰县| 兰坪| 新津县| 崇左市| 烟台市| 永济市| 连江县| 迭部县| 武宁县| 遂平县| 台前县| 蓝山县| 辽中县| 尼木县| 大港区| 叙永县| 敖汉旗| 江达县| 临邑县| 霍山县| 河东区| 旬阳县| 汾西县| 长沙市| 阳西县| 叶城县| 东台市| 桐柏县| 宁武县| 张掖市| 玉树县| 玛曲县| 礼泉县| 五原县| 屏山县| 花莲县| 丹棱县| 高陵县| 高阳县| 上犹县|