经常有遇到说浏览器与flash之间不好debug,数据不好交流,确实每次遇到都得多写些代码。麻烦!
这回我打算写个flash类,专门用来解决这些问题。这几天,我就先从cookie的读写开始,写了个cookie类,有了这个类,以后我就能直接在flash里面操作cookie了。一劳永逸,大伙如果觉得有用就拿去吧。我已经放在了google code上面, 地址: http://code.google.com/p/swc-flashcookie/
我们来看看我用它来做的效果:http://www.xoedge.com/sweeps/zex/playwithcookie/
把我这段用于测试的代码也附上,实在看不懂我写的swc使用说明,您就直接看这段代码,应该就行了。哈哈。
package {import flash.display.MovieClip;import fl.controls.*;import flash.events.MouseEvent;import com.santiago.flash.cookie.Cookie;public class Main extends MovieClip {public function Main() {/** 1.sets of getCookie * getCookieBtn & getCookieName** 2.sets of setCookie* setCookieBtn & setCookieName & setCookieValue* * 3.sets of deleteCookie* deleteCookieName & deleteCookieBtn** 3.sets of result* result * */getCookieName.tabIndex = 1;getCookieBtn.tabIndex = 2;setCookieName.tabIndex = 3;setCookieValue.tabIndex = 4;setCookieBtn.tabIndex = 5;deleteCookieName.tabIndex = 6;deleteCookieBtn.tabIndex = 7;result.tabIndex = 8;getCookieBtn.addEventListener(MouseEvent.CLICK, getCookieHandler);setCookieBtn.addEventListener(MouseEvent.CLICK, setCookieHandler);deleteCookieBtn.addEventListener(MouseEvent.CLICK, deleteCookieHandler);}private function setCookieHandler(event:MouseEvent):void{var _name:String = setCookieName.text;var _value:String = setCookieValue.text;setCookieName.text = setCookieValue.text = '';var mes:String;if(_name&&_value){Cookie.instance().write(_name, _value);mes = 'you have just set cookies successfully' + ' cookieName is: ' + _name + ' itsValue is: ' + Cookie.instance().read(_name) ;}else{mes = 'you have not set any cookies successfully by now';}showResult(mes)}private function getCookieHandler(event:MouseEvent):void{var target:String = getCookieName.text;var cookieResult:String;if(Cookie.instance().read(target) == null || Cookie.instance().read(target)== ''){cookieResult = 'no related cookie by now'}else{ cookieResult = target+' cookie is: '+ Cookie.instance().read(target)}getCookieName.text = '';showResult(cookieResult)}private function deleteCookieHandler(event:MouseEvent):void{var target:String = deleteCookieName.text;var cookieResult:String;//= target + ' cookie has been deleted'if(target == null || target == ''){cookieResult = 'Please define what cookie you want to delete firstly.'}else{if(Cookie.instance().read(target) == null || Cookie.instance().read(target)== ''){cookieResult = 'No such a cookie needs to be deleted.'}else{Cookie.instance().erase(target);cookieResult = 'it has been deleted successfully.';}}showResult(cookieResult)}private function showResult(contents:String){result.text = contents;}}}