{"id":105,"date":"2010-08-25T12:57:42","date_gmt":"2010-08-25T11:57:42","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=105"},"modified":"2010-08-25T13:21:52","modified_gmt":"2010-08-25T12:21:52","slug":"urlloader-and-loader-classes","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2010\/08\/25\/urlloader-and-loader-classes\/","title":{"rendered":"URLLoader and Loader classes"},"content":{"rendered":"<p>Have you ever had mystery errors that your content stopped working without a reason? Possibly you haven&#8217;t registered all important listeners, most examples are simplified, i.e.<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar image:Loader = new Loader();\r\nimage.addeventListener(Event.COMPLETE, onImageLoaded);\r\nimage.load(new URLRequest(&quot;myImage.jpg&quot;));\r\n<\/pre>\n<p><!--more--><br \/>\nand this is fine as long:<br \/>\n&#8211; file exist<br \/>\n&#8211; your flash can access this resource<br \/>\n&#8211; you have debug version of flash player (it doesn&#8217;t stop error but it throws them in your face:) )<\/p>\n<p>basically you should get a habit of listening for ALL important events: IOErrorEvent.IO_ERROR and SecurityErrorEvent.SECURITY_ERROR, those two are really important and will save you a lot of trouble. So revised example will look like follows:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar image:Loader = new Loader();\r\nimage.addeventListener(IOErrorEvent.IO_ERROR, onImageError, false, 0, true);\r\nimage.addeventListener(SecurityErrorEvent.SECURITY_ERROR, onImageError, false, 0, true);\r\nimage.addeventListener(Event.COMPLETE, onImageLoaded, false, 0, true);\r\nimage.load(new URLRequest(&quot;myImage.jpg&quot;));\r\n\r\n\/\/somwhere later\r\nfunction onImageError(e:Event):void\r\n{\r\n    \/\/do something with the error, log it handle it (fall-back image) etc.\r\n}\r\n<\/pre>\n<p>happy coding<br \/>\np.s. title says about Loader and URLLoader as most frequently used but it is applicable to any Class that access external resource.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever had mystery errors that your content stopped working without a reason? Possibly you haven&#8217;t registered all important listeners, most examples are simplified, i.e.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[17,9],"tags":[12,19,18],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/105"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":5,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/105\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}