URLLoaderBase.as 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. Copyright (c) 2008, Adobe Systems Incorporated
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of Adobe Systems Incorporated nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. package com.adobe.webapis
  28. {
  29. import flash.events.IOErrorEvent;
  30. import flash.events.SecurityErrorEvent;
  31. import flash.events.ProgressEvent;
  32. import com.adobe.net.DynamicURLLoader;
  33. /**
  34. * Dispatched when data is
  35. * received as the download operation progresses.
  36. *
  37. * @eventType flash.events.ProgressEvent.PROGRESS
  38. *
  39. * @langversion ActionScript 3.0
  40. * @playerversion Flash 9.0
  41. */
  42. [Event(name="progress", type="flash.events.ProgressEvent")]
  43. /**
  44. * Dispatched if a call to the server results in a fatal
  45. * error that terminates the download.
  46. *
  47. * @eventType flash.events.IOErrorEvent.IO_ERROR
  48. *
  49. * @langversion ActionScript 3.0
  50. * @playerversion Flash 9.0
  51. */
  52. [Event(name="ioError", type="flash.events.IOErrorEvent")]
  53. /**
  54. * A securityError event occurs if a call attempts to
  55. * load data from a server outside the security sandbox.
  56. *
  57. * @eventType flash.events.SecurityErrorEvent.SECURITY_ERROR
  58. *
  59. * @langversion ActionScript 3.0
  60. * @playerversion Flash 9.0
  61. */
  62. [Event(name="securityError", type="flash.events.SecurityErrorEvent")]
  63. /**
  64. * Base class for services that utilize URLLoader
  65. * to communicate with remote APIs / Services.
  66. *
  67. * @langversion ActionScript 3.0
  68. * @playerversion Flash 9.0
  69. */
  70. public class URLLoaderBase extends ServiceBase
  71. {
  72. protected function getURLLoader():DynamicURLLoader
  73. {
  74. var loader:DynamicURLLoader = new DynamicURLLoader();
  75. loader.addEventListener("progress", onProgress);
  76. loader.addEventListener("ioError", onIOError);
  77. loader.addEventListener("securityError", onSecurityError);
  78. return loader;
  79. }
  80. private function onIOError(event:IOErrorEvent):void
  81. {
  82. dispatchEvent(event);
  83. }
  84. private function onSecurityError(event:SecurityErrorEvent):void
  85. {
  86. dispatchEvent(event);
  87. }
  88. private function onProgress(event:ProgressEvent):void
  89. {
  90. dispatchEvent(event);
  91. }
  92. }
  93. }