用ShareObject在本地保存数据(下面帖子有篇文章将较详细讲解)RIA|RIA电子书|RIA论坛|RIA源文件/ F0 I$ E. d8 p: }1 L2 z9 i
例(本地保存数据,要想远程保存数据,也可以,跟下边的例子差不多,只不过要安装 flashcom 需要$ 蛮贵的)
0 Z' s& z/ @$ }中国最大的RIA分享社区-与中国闪客一起成长和发展!package {中国最大的RIA分享社区-与中国闪客一起成长和发展!& j3 k: P* z+ ?2 \# o" j" @ A! _0 Y
/*****************************************************************************
9 V2 Z3 X5 x* V) t. ]$ I8 Z6 j8 QRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 SharedObject 类用于在用户计算机或服务器上读取和存储有限的数据量。 使用共享对象,ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application {- n6 L7 i% b0 Z% J
可在永久贮存在本地计算机或远程服务器上的多个客户端 SWF 文件和对象之间实现实时
. d) r, I0 g4 F4 twww.52ria.com 数据共享。 本地共享对象类似于浏览器 Cookie,远程共享对象类似于实时数据传输设备。
, }. B0 ]- X9 H+ v3 n J) {RIA|RIA电子书|RIA论坛|RIA源文件 若要使用远程共享对象,则需要一个服务器(如 Adobe Flex 或 Adobe 的 Macromedia
- a. A+ q! ~' S% H- U8 \+ t$ i! cria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application Flash Media Server 2)。
2 z& h' i; m7 M$ u2 j/ b1 V1 wRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 *****************************************************************************/中国最大的RIA分享社区-与中国闪客一起成长和发展!0 e/ D' ]# t' y: [! Z8 \+ C+ `
/ c* p0 q0 x4 \
RIA|RIA电子书|RIA论坛|RIA源文件" c9 N4 Y* o9 s( _' b
ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application) D/ P9 B" i2 P* f3 Z
import flash.display.Sprite;ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application+ q2 C Q4 V( d' p' J
import flash.events.MouseEvent;
- k7 _, p8 b" y, S! kRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 import flash.events.NetStatusEvent;
4 L6 J X9 l/ g* N" Kwww.52ria.com import flash.net.SharedObject;
7 x& l$ [6 a) y' Y5 ]+ ]: n/ ^; A' yria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application import flash.net.SharedObjectFlushStatus;
3 p1 n$ s4 j7 M1 L$ U中国最大的RIA分享社区-与中国闪客一起成长和发展! import flash.text.TextField;
$ q" C e0 Z& iwww.52ria.com import flash.text.TextFieldAutoSize;中国最大的RIA分享社区-与中国闪客一起成长和发展!3 y8 I- ?% u+ Z8 y2 ~/ z
import flash.text.TextFieldType;www.52ria.com" O: o7 O+ C0 \5 B
中国最大的RIA分享社区-与中国闪客一起成长和发展!, o0 Q9 H) @# [/ M' T0 k
public class SO extends Sprite {RIA|RIA电子书|RIA论坛|RIA源文件* I% Y# h- @6 K
; l# K$ j1 e( w1 Y. n6 y! e, Dwww.52ria.com private var mySo:SharedObject;
/ d f5 S4 s' F# H8 U private var inputLbl:TextField;中国最大的RIA分享社区-与中国闪客一起成长和发展!% ]1 _( ]/ P' Q) p6 F
private var input:TextField;www.52ria.com2 \5 R1 A# W' ] Z3 N0 q2 @
private var output:TextField;
* ]9 W0 E+ ]7 G, N ^& sria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application private var saveBtn:Sprite;中国最大的RIA分享社区-与中国闪客一起成长和发展!) H- _: `+ Z2 L9 l+ u8 I
private var clearBtn:Sprite;
. l& _+ {8 h& c/ Mwww.52ria.com public function SO() {ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application' ]' |7 i c7 O- w" o1 ?7 r* R$ t& d
www.52ria.com' e4 y* o. j' b4 O
buildUI();////这是创建界面函数; x2 o- }8 z4 {' O$ D
ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application* L5 C( w- y% q1 e' H
/////对按钮添加侦听
# l) Z+ Y: x6 d; t F( j saveBtn.addEventListener(MouseEvent.CLICK, saveValue);
" w' w( j1 ^1 S( ^$ L0 h( z6 gRIA|RIA电子书|RIA论坛|RIA源文件 clearBtn.addEventListener(MouseEvent.CLICK, clearValue);
$ E' w7 o! @/ R# S8 \' f% |0 zRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方www.52ria.com9 O9 u$ \ d6 n- k1 D
mySo = SharedObject.getLocal("application-name");
4 C" F! S; ~/ }9 T; o% a中国最大的RIA分享社区-与中国闪客一起成长和发展! output.appendText("SharedObject loaded...\n");RIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 i2 C* I0 b, r8 A0 c, I
output.appendText("loaded value: " + mySo.data.savedValue + "\n\n");
+ D! {! u- r8 V: t" o# ewww.52ria.com }
2 _5 G$ j6 K; t$ f3 J
: B* x; g* q }0 j中国最大的RIA分享社区-与中国闪客一起成长和发展! private function saveValue(event:MouseEvent):void {
6 \- i! }7 q" u. A# J8 LRIA|RIA电子书|RIA论坛|RIA源文件 output.appendText("saving value...\n");www.52ria.com1 M6 O0 i) c- w( B2 r) b' v
mySo.data.savedValue = input.text;
Z" f+ h8 V- P8 \( B; ?
0 i* K N, E7 V3 r) U) D4 zRIA|RIA电子书|RIA论坛|RIA源文件 var flushStatus:String = null;RIA|RIA电子书|RIA论坛|RIA源文件$ G4 s8 L% R- ^% o6 L2 \
try {RIA|RIA电子书|RIA论坛|RIA源文件% ?$ {$ j7 `4 L3 _$ V2 o
flushStatus = mySo.flush(10000);. a+ B( b, p- n
} catch (error:Error) {
6 O4 O! z$ b1 Z* f$ F" l% URIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 output.appendText("Error...Could not write SharedObject to disk\n");) F& Q7 E( S* {9 u$ l% v
}
' B& F! I/ {6 v( Y4 D if (flushStatus != null) {www.52ria.com, m/ H4 L* F5 y7 ]- \" x
switch (flushStatus) {
: w: c# b0 Z- f( Q$ B4 qRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 case SharedObjectFlushStatus.PENDING :
& B# _/ D$ o2 C( _" D* p1 _, \RIA|RIA电子书|RIA论坛|RIA源文件 output.appendText("Requesting permission to save object...\n");
/ w/ ]. N5 W! r3 l) a mySo.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);RIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方/ g1 p1 K; c) ~+ @. Z
break;中国最大的RIA分享社区-与中国闪客一起成长和发展!0 {! m6 u0 r3 U4 s2 Q) Z
case SharedObjectFlushStatus.FLUSHED :
; X7 X$ u( e, ]9 `www.52ria.com output.appendText("Value flushed to disk.\n");中国最大的RIA分享社区-与中国闪客一起成长和发展!, p0 F0 v9 S, L5 h' @: |9 M
break;RIA|RIA电子书|RIA论坛|RIA源文件" W9 h+ U7 s8 t& d7 \
}
' i6 a" n8 Z6 l# L, E6 jRIA|RIA电子书|RIA论坛|RIA源文件 }RIA|RIA电子书|RIA论坛|RIA源文件- T( P* }; I0 S% [/ R7 z# C: p
output.appendText("\n");ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application$ K- o5 P/ u6 E& l# F
}RIA|RIA电子书|RIA论坛|RIA源文件* h# r7 w; ^3 `6 N
private function clearValue(event:MouseEvent):void {* A% `( i0 R; @( e( Z" u8 B) [
output.appendText("Cleared saved value...Reload SWF and the value should be \"undefined\".\n\n");www.52ria.com- v1 u- J. Q9 C
delete mySo.data.savedValue;RIA|RIA电子书|RIA论坛|RIA源文件' \1 X3 T; o' P7 H3 p9 o
}
6 u! M4 l. R4 e, h. B5 |% ]* e7 ~, \www.52ria.com private function onFlushStatus(event:NetStatusEvent):void {
3 t6 ?+ x' v/ @% G+ r* o: R3 fRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 output.appendText("User closed permission dialog...\n");
& V/ Y! Z& I% |( f switch (event.info.code) {
6 e; a# a D8 @ case "SharedObject.Flush.Success" :RIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方6 q$ G: V1 m/ e8 S2 D, m
output.appendText("User granted permission -- value saved.\n");
& f, v+ ~" b- d9 yRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 break;RIA|RIA电子书|RIA论坛|RIA源文件* R0 R0 k% T2 R" M2 D
case "SharedObject.Flush.Failed" :
# F. a# l( I4 K" W5 _RIA|RIA电子书|RIA论坛|RIA源文件 output.appendText("User denied permission -- value not saved.\n");中国最大的RIA分享社区-与中国闪客一起成长和发展!2 j/ E* }6 l8 G; y
break;ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application3 J% t3 S, o% u/ R
}RIA|RIA电子书|RIA论坛|RIA源文件4 o1 A4 Z- }" R5 A+ p
output.appendText("\n");
2 ]4 f( K; _: M: L+ N0 u, Uria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet applicationRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方. _" A/ d% A' o5 [! C/ v; r
mySo.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application0 Y3 C' _3 S7 {! u3 t! z( z
}
; S# w2 ?7 o. t- s( Q5 z5 zRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 // UI elements中国最大的RIA分享社区-与中国闪客一起成长和发展!' _" Z, ]7 E% h5 A
% k) @' ?+ d S: U; XRIA|RIA电子书|RIA论坛|RIA源文件 ////创建界面
7 S: h, ^9 r4 f' y. i& hria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application private function buildUI():void {
& D+ d. s$ i/ S; Z4 W' C+ T5 ^, kRIA|RIA电子书|RIA论坛|RIA源文件 // input labelwww.52ria.com) P8 x+ @7 o7 R# F2 `
inputLbl = new TextField();
. d w, ~$ y0 H4 K/ _4 Oria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application addChild(inputLbl);
' J. y/ k5 Q, ~; O6 p K inputLbl.x = 10;RIA|RIA电子书|RIA论坛|RIA源文件/ n# @. C8 L5 P
inputLbl.y = 10;中国最大的RIA分享社区-与中国闪客一起成长和发展!0 J# }5 x! Y8 n, }1 a( d$ A
inputLbl.text = "Value to save:";中国最大的RIA分享社区-与中国闪客一起成长和发展!% A; G; F& w" m. _/ @* c/ ?
0 \- |) v7 ^, q' ]* {# v' s; fRIA|RIA电子书|RIA论坛|RIA源文件 // input TextField
0 E9 U% _( x( uwww.52ria.com input = new TextField();
, R4 Q6 \; M; w1 x中国最大的RIA分享社区-与中国闪客一起成长和发展! addChild(input);
, r% @0 Z/ z9 e: b! D# ~ input.x = 80;www.52ria.com" i9 R# H& z+ c# Q0 |
input.y = 10;www.52ria.com4 ]+ a t3 ~: s! z. Z
input.width = 100;中国最大的RIA分享社区-与中国闪客一起成长和发展!) W9 s- s7 v. D4 @ q) T! I" p* u
input.height = 20;RIA|RIA电子书|RIA论坛|RIA源文件' C J4 n. p1 Y5 H; b0 @" f: Q
input.border = true;
7 O7 i4 g0 I7 v4 n. v input.background = true;
( T- e' U0 m- b3 ?+ N中国最大的RIA分享社区-与中国闪客一起成长和发展! input.type = TextFieldType.INPUT;
. R& {3 p1 g( d$ I+ h8 N9 S
) G2 r2 s! U5 m9 n. e( | ~RIA|RIA电子书|RIA论坛|RIA源文件 // output TextFieldRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方7 N* ?2 h" k' w1 M5 T
output = new TextField();RIA|RIA电子书|RIA论坛|RIA源文件& x4 j4 z' T0 g2 q9 c
addChild(output);
4 ?- U7 n! w, Y, f7 |2 zRIA|RIA电子书|RIA论坛|RIA源文件 output.x = 10;RIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 x3 b# O# [1 P
output.y = 35;中国最大的RIA分享社区-与中国闪客一起成长和发展!- |1 O" O- [+ t; h% ?5 r. k
output.width = 250;% ^* p) n) ^+ H _+ U7 R; \
output.height = 250;5 ]( w& S* j% @4 u" g+ y6 ^
output.multiline = true;www.52ria.com) n$ R+ E# j3 e' v6 J3 F' ^
output.wordWrap = true;* R5 W! w% j/ S/ a& e% S$ ~
output.border = true;4 t% h; Z" M+ \! K) g, r
output.background = true;RIA|RIA电子书|RIA论坛|RIA源文件" j w7 b" E3 m9 ^7 F- a0 j
中国最大的RIA分享社区-与中国闪客一起成长和发展!: N0 I# e: Y0 ?+ _0 D: w
// Save buttonRIA|RIA电子书|RIA论坛|RIA源文件" z' h$ w( b+ M1 H/ o
saveBtn = new Sprite();
$ k- u: B! k' _6 ~- k( URIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 addChild(saveBtn);
1 E B3 z ]5 U# R1 rwww.52ria.com saveBtn.x = 190;
# h6 F# e1 M! ]2 j" @ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application saveBtn.y = 10;
9 T4 \4 K! i, Q( z中国最大的RIA分享社区-与中国闪客一起成长和发展! saveBtn.useHandCursor = true;
B' H9 r) E) N- n: l' hria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application saveBtn.graphics.lineStyle(1);
1 g2 F# P7 A7 |. A) J2 \, y/ gria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application saveBtn.graphics.beginFill(0xcccccc);
) _# N# U0 }2 z7 owww.52ria.com saveBtn.graphics.drawRoundRect(0, 0, 30, 20, 5, 5);
- O$ M: d) G* ]www.52ria.com var saveLbl:TextField = new TextField();
# A J3 ~! V* B) y saveBtn.addChild(saveLbl);www.52ria.com u" P: K9 K: X: u1 `5 Z" Z+ H g
saveLbl.text = "Save";
+ e: C( A3 }: P, W" X0 l# Q3 Z saveLbl.selectable = false;
/ }8 h" r+ f9 \+ ARIA|RIA电子书|RIA论坛|RIA源文件/ w1 M/ G; c3 b. u# S* G
// Clear buttonRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方" X/ }, i8 \, T
clearBtn = new Sprite();
X8 N3 k5 I% b4 W g0 r! `www.52ria.com addChild(clearBtn);
3 z/ g8 d) o2 ]% h( c; uRIA|RIA电子书|RIA论坛|RIA源文件 clearBtn.x = 230;RIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方) k; {$ q' v# u) V6 ~: }8 `
clearBtn.y = 10;
; f/ r8 _2 g- b中国最大的RIA分享社区-与中国闪客一起成长和发展! clearBtn.useHandCursor = true;
+ k6 G( Z1 S( ^" D1 P1 N) Uria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application clearBtn.graphics.lineStyle(1);ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application# Y N) J e- T3 s0 R+ s) u
clearBtn.graphics.beginFill(0xcccccc);
2 ]" @) O: h/ C0 @0 |) y2 F中国最大的RIA分享社区-与中国闪客一起成长和发展! clearBtn.graphics.drawRoundRect(0, 0, 30, 20, 5, 5);
0 i: d9 T0 J; x& y4 h中国最大的RIA分享社区-与中国闪客一起成长和发展! var clearLbl:TextField = new TextField();RIA|RIA电子书|RIA论坛|RIA源文件 p _4 o% C# _6 I' \, ?0 c2 g
clearBtn.addChild(clearLbl);
2 i5 t- k' t7 E9 XRIA是Rich Internet Applications的缩写,52RIA.com[我爱RIA网]是中国第一个以RIA开源为主的网站,还包括Flex,Flash,Ajax等RIA技术开源地方 clearLbl.text = "Clear";www.52ria.com3 c0 h( w ~, C; L0 i. s
clearLbl.selectable = false;ria开源, ria技术 ria应用,ria教程,ria开发,flashria,flash,rich internet application( b* k# L3 }" `: V6 |# f2 x
}
5 z- N4 x( r5 ~4 G; k3 N: KRIA|RIA电子书|RIA论坛|RIA源文件 }中国最大的RIA分享社区-与中国闪客一起成长和发展!' I" W0 x' q* X0 a2 J
}