2019-1-18 zhulinan Flash
用escape()函数将文本转成URL编码后存入mysql数据库,用JSON读取数据时可避免特殊字符如单双引号的干扰。
as代码参考: package { import flash.display.MovieClip; import flash.display.Loader; import flash.display.LoaderInfo; import flash.events.*; import flash.net.*; public class T4 extends MovieClip { private var _at:String = ""; public function T4() { addEventListener(Event.ADDED_TO_STAGE, addedHandler); } private function addedHandler(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, addedHandler); btnSave.addEventListener(MouseEvent.CLICK, btnSaveClickHandler); btnLoad.addEventListener(MouseEvent.CLICK, btnLoadClickHandler); } private function btnSaveClickHandler(e:MouseEvent):void { if (_at != "" ) return; _at = "保存"; var urlLoader:URLLoader = new URLLoader(); var urlRequest:URLRequest = new URLRequest(); var vars:URLVariables = new URLVariables(); urlRequest.url = "articleSave.php"; vars.accessKey = "i am elight"; vars.uid = 1; vars.upwd = "Elight"; vars.aid = 1; vars.atitle = "This is a test"; vars.adata = escape(txt1.text); urlRequest.method = URLRequestMethod.POST; urlRequest.data = vars; urlLoader.load(urlRequest); urlLoader.addEventListener(Event.COMPLETE, ldCompleteHandle); urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ldSecurityErrorHandle); urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ldIoErrorHandle); } private function btnLoadClickHandler(e:MouseEvent):void { if (_at != "" ) return; _at = "加载"; var urlLoader:URLLoader = new URLLoader(); var urlRequest:URLRequest = new URLRequest(); var vars:URLVariables = new URLVariables(); urlRequest.url = "articleLoad.php"; vars.accessKey = "i am elight"; vars.uid = 1; vars.upwd = "Elight"; vars.aid = 1; urlRequest.method = URLRequestMethod.POST; urlRequest.data = vars; urlLoader.load(urlRequest); urlLoader.addEventListener(Event.COMPLETE, ldCompleteHandle); urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ldSecurityErrorHandle); urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ldIoErrorHandle); } private function ldCompleteHandle(e:Event):void { e.target.removeEventListener(Event.COMPLETE, ldCompleteHandle); var loader:URLLoader = URLLoader(e.target); var rel:*; try { rel = JSON.parse(loader.data); } catch (error:Error) { txtTs.text = _at + "数据处理失败:errorId=1"; _at = ""; return; } if (rel.result == "0") { txtTs.text = _at + "数据成功!"; if (_at == "加载") { txt2.text = unescape(rel.data); } } else { txtTs.text = _at + "数据失败:" + rel.result; } _at = ""; } private function ldSecurityErrorHandle(e:SecurityErrorEvent):void { txtTs.text = "对不起,连接服务器失败(SecurityError)!"; } private function ldIoErrorHandle(e:IOErrorEvent):void { txtTs.text = "对不起,连接服务器失败(IoError)!"; } } }
下列字符escape()函数不转换为转义序列: 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z @ - _ . * + /