{"id":230,"date":"2009-04-13T23:08:47","date_gmt":"2009-04-13T15:08:47","guid":{"rendered":"http:\/\/www.wlash.com\/blog\/?p=230"},"modified":"2009-04-13T23:08:47","modified_gmt":"2009-04-13T15:08:47","slug":"extend-flasheventsevent","status":"publish","type":"post","link":"https:\/\/blog2.wwhhoo.com\/?p=230","title":{"rendered":"extend flash.events.Event"},"content":{"rendered":"<p>\u5f53\u4f60\u81ea\u5b9a\u4e49\u5e76\u7ee7\u627fEvent\u7c7b\u65f6\uff0c\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u65b9\u6cd5\u5fc5\u987b\u8986\u76d6\u3002<!--more-->\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662fEvent.clone():Event<\/p>\n<p>Flash CS3\u4e2d\u7684\u4e2d\u6587\u5e2e\u52a9\u5199\u5f97\u5f88\u7b80\u5355\uff0c\u5e76\u6ca1\u6709\u8bf4\u660e\u4ec0\u4e48\u539f\u56e0\u3002<\/p>\n<p>\u539f\u56e0\u662f<code>dispatchEvent(<strong>e<\/strong>:Event)<\/code>\u65b9\u6cd5\uff0c\u5982\u679c<strong>e<\/strong>\u4e0d\u662f\u901a\u8fc7:<\/p>\n<pre lang=\"actionscript\">\nvar e:CustomEvent = new CustomEvent('custom');\n\/\/\u5e7f\u64ade\u4e8b\u4ef6\ndispatchEvent(e);\/\/e\u4e0d\u4f1a\u8c03\u7528e.clone();\u65b9\u6cd5\n<\/pre>\n<p>\n&nbsp; \u800c\u662f\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u5f97\u7684:<\/p>\n<pre lang=\"actionscript\">\naddEventListener('custom', customFunc);\n\/\/\u6b64\u65b9\u6cd5\u6765\u81ea\u76d1\u542cCustomEvent\u7684'custom'\u4e8b\u4ef6\nfunction customFunc(e:CustomEvent):void{\n   \/\/\u518d\u5e7f\u64ad\u6b64\u4e8b\u4ef6\n   dispatchEvent(e);\/\/\u8fd9\u65f6e\u4f1a\u8c03\u7528e.clone();\u65b9\u6cd5\n}\n<\/pre>\n<p>&nbsp;\u5982\u679c\u4e0d\u91cd\u65b0\u5b9a\u4e49e.clone()\u65b9\u6cd5\uff0c\u5219\u6267\u884cdispatchEvent(e)\u65f6\uff0c\u4f1a\u81ea\u52a8\u8c03\u7528CustomEvent\u7236\u7c7b(Event)\u7684clone()\u65b9\u6cd5\uff0c\u5219clone\u51fa\u6765\u7684\u4e8b\u4ef6\u662fEvent\u800c\u4e0d\u662f\u81ea\u5b9a\u4e49\u7684CustomEvent\uff0c\u5bf9\u4e8eCustomEvent\u91cc\u6dfb\u52a0\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u5c31\u4e0d\u4f1a\u5b58\u5728\uff0c\u56e0\u4e3a\u5e7f\u64ad\u51fa\u53bb\u7684\u4e8b\u4ef6\u4e3aEvent\u7c7b\u800c\u4e0d\u662fCustomEvent\u7c7b\u3002<\/p>\n<p>&nbsp;\u4ee5\u6b64\u7c7b\u662f\u6211\u81ea\u5b9a\u4e49\u7684\u4e00\u4e2aWebservice\u7c7b\u7684\u4e8b\u4ef6\u7c7b\u3002<\/p>\n<pre lang=\"actionscript\">\npackage com.wlash.data {\n\n\timport flash.events.Event;\n\t\n\t\n\t\/**\n\t * WebservicesEvent.\n\t * annotate here for this class.\n\t * \n\t *\/\n\tpublic class WebServicesEvent extends Event {\n\t\t\n\t\t\/** those value are 'URL.Not.Found', 'Call.Error', 'Security.Error', 'Call.Security.Error' *\/\n\t\tpublic var code:String;\n\t\t\/** detail infomation *\/\n\t\tpublic var info:String;\n\t\t\/** call remote method name *\/\n\t\tpublic var method:String;\n\t\t\n\t\t\/\/*************************[READ|WRITE]*************************************\/\/\n\t\t\n\t\t\n\t\t\/\/*************************[READ ONLY]**************************************\/\/\n\t\t\n\t\t\n\t\t\/\/*************************[STATIC]*****************************************\/\/\n\t\t\/**\n\t\t* define <code>ioerror<\/code> event, when call remote method error or can't find the webservices url.\n\t\t* <code>code<\/code> is 'URL.Not.Found' or 'Call.Error'.\n\t\t* @eventType callSecurityError\n\t\t*\/\n\t\tstatic public const IO_ERROR:String\t\t\t\t=\t'ioerror';\n\t\t\/**\n\t\t* define <code>securityError<\/code> event, when call remote method security error.\n\t\t* <code>code<\/code> is 'Security.Error' or 'Call.Security.Error'.\n\t\t* @eventType securityError\n\t\t*\/\n\t\tstatic public const SECURITY_ERROR:String\t\t=\t'securityError';\n\t\t\n\t\n\t\t\/**\n\t\t * CONSTRUCTION FUNCTION.\n\t\t * Create this class BY [new WebservicesEvent();]\n\t\t * @param\ttype like IO_ERROR, SECURITY_ERROR ...\n\t\t * @param\tcode value are  Call.Error or Security.Error or URL.Not.Found or Call.Security.Error.\n\t\t * @param\tinfo the detail infomation\n\t\t * @param\tmethod method name if not null\n\t\t *\/\n\t\tpublic function WebServicesEvent(type:String, code:String='',info:String='',method:String=null) {\n\t\t\t\/\/\u53c2\u7167Adobe Event\u7684\u5b50\u7c7b\uff0c\u6784\u9020\u51fd\u6570\u81f3\u5c11\u6709\u4e09\u4e2a\u53c2\u6570,(type, bubbles, cancelable)\u4e09\u4e2a\u53c2\u6570\uff0c\u867d\u7136\u5bf9\u4e8e\u90e8\u5206Event\u7684\u5b50\u7c7b\u540e\u4e24\u4e2a\u53c2\u6570\u662f\u65e0\u7528\u7684\uff0c\u4f46\u4e5f\u5b9a\u4e49\u3002\u5982\u679c\u518d\u6709\u989d\u5916\u7684\u53c2\u6570\uff0c\u5219\u662f\u5728cancelable\u540e\u8fb9\u7ee7\u7eed\u5b9a\u4e49\u3002\n\t\t\t\/\/\u6211\u5728\u8fd9\u91cc\u662f\u8d2a\u56fe\u65b9\u4fbf\u5e76\u6ca1\u6709\u6309\u7167Adobe\u7684\u65b9\u6cd5\u6765\u5b9a\u4e49Event\u7684\u5b50\u7c7b\n\t\t\tsuper(type, false, false);\n\t\t\tthis.info\t=\tinfo;\n\t\t\tthis.code\t=\tcode;\n\t\t\tthis.method\t=\tmethod;\n\t\t}\n\t\t\/\/*************************[PUBLIC METHOD]**********************************\/\/\n\t\t\/**\n\t\t * format output data\n\t\t * @return [Event=WebServicesEvent, type, code, info, method, data]\n\t\t *\/\n\t\toverride public function toString():String {\n\t\t\t\/\/\u5982\u679c\u91cd\u65b0\u5b9a\u4e49\u6b64\u7c7b\uff0c\u53ef\u4ee5\u901a\u8fc7trace(e)\u5f97\u5230\u81ea\u5b9a\u4e49\u7684\u683c\u5f0f\uff0c\u4e0d\u662f\u5fc5\u8981\u7684\u3002\n\t\t\treturn formatToString('WebServicesEvent:', 'type', 'code', 'info', 'method');\n\t\t}\n\t\t\n\t\t\/**\n\t\t * @inheritDoc \n\t\t *\/\n\t\toverride public function clone():Event {\n\t\t\t\/\/\u5fc5\u987b\u8986\u76d6\u6b64\u65b9\u6cd5\uff0c\u4e14\u8fd4\u56de\u503c\u53ea\u80fd\u4e3aEvent\uff0c\u800c\u4e0d\u662f\u81ea\u5b9a\u4e49\u7684WebServicesEvent.\n\t\t\t\/\/\u5f53\u8981\u76d1\u542c\u51fd\u6570\u4e2d\u63a5\u6536\u5230\u6b64\u4e8b\u4ef6\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528WebServicesEvent(e)\u6216e as WebServicesEvent\u65b9\u5f0f\u8f6c\u4e3aWebServicesEvent\u7c7b\u3002\n\t\t\treturn new WebServicesEvent(type, code, info, method);\n\t\t}\n\t\t\/\/*************************[INTERNAL METHOD]********************************\/\/\n\t\t\n\t\t\n\t\t\/\/*************************[PROTECTED METHOD]*******************************\/\/\n\t\t\n\t\t\n\t\t\/\/*************************[PRIVATE METHOD]*********************************\/\/\n\t\t\n\t\t\n\t\t\n\t\t\n\n\t\t\n\t\t\/\/*************************[STATIC METHOD]**********************************\/\/\n\t\t\n\t\t\n\t}\n}\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u81ea\u5b9a\u4e49\u5e76\u7ee7\u627fEvent\u7c7b\u65f6\uff0c\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u65b9\u6cd5\u5fc5\u987b\u8986\u76d6\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[9],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-6","tag-as3"],"_links":{"self":[{"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":0,"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog2.wwhhoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}