/lib/osmf/player/StrobeMediaPlayback/src/org/osmf/player/configuration/ConfigurationLoader.as

https://github.com/tvcok/flash · ActionScript · 90 lines · 52 code · 10 blank · 28 comment · 3 complexity · 359da4bd66eca5c4b9da1a5ef8103ae6 MD5 · raw file

  1. /***********************************************************
  2. * Copyright 2010 Adobe Systems Incorporated. All Rights Reserved.
  3. *
  4. * *********************************************************
  5. * The contents of this file are subject to the Berkeley Software Distribution (BSD) Licence
  6. * (the "License"); you may not use this file except in
  7. * compliance with the License.
  8. *
  9. * Software distributed under the License is distributed on an "AS IS"
  10. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  11. * License for the specific language governing rights and limitations
  12. * under the License.
  13. *
  14. *
  15. * The Initial Developer of the Original Code is Adobe Systems Incorporated.
  16. * Portions created by Adobe Systems Incorporated are Copyright (C) 2010 Adobe Systems
  17. * Incorporated. All Rights Reserved.
  18. *
  19. **********************************************************/
  20. package org.osmf.player.configuration
  21. {
  22. import flash.events.Event;
  23. import flash.events.EventDispatcher;
  24. import flash.events.IOErrorEvent;
  25. import flash.events.SecurityErrorEvent;
  26. import flash.net.URLLoader;
  27. import flash.net.URLRequest;
  28. import org.osmf.player.chrome.configuration.ConfigurationUtils;
  29. [Event(name="complete", type="flash.events.Event")]
  30. /**
  31. * Loads a configuration model from flashvars and external configuration files.
  32. */
  33. public class ConfigurationLoader extends EventDispatcher
  34. {
  35. public function ConfigurationLoader(configurationDeserializer:ConfigurationFlashvarsDeserializer, xmlDeserializer:ConfigurationXMLDeserializer)
  36. {
  37. this.flashvarsDeserializer = configurationDeserializer;
  38. this.xmlDeserializer = xmlDeserializer;
  39. }
  40. public function load(parameters:Object, configuration:PlayerConfiguration):void
  41. {
  42. // Parse configuration from the parameters passed on embedding
  43. // StrobeMediaPlayback.swf:
  44. if (parameters.hasOwnProperty("configuration"))
  45. {
  46. var configurationContent:String = parameters["configuration"];
  47. // if ((configurationContent.toLowerCase().lastIndexOf(".xml") == (configurationContent.length - 4)))
  48. {
  49. var loader:XMLFileLoader = new XMLFileLoader();
  50. loader.addEventListener(Event.COMPLETE, loadConfiguration);
  51. loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadConfiguration);
  52. loader.addEventListener(IOErrorEvent.IO_ERROR, loadConfiguration);
  53. function loadConfiguration(event:Event):void
  54. {
  55. loader.removeEventListener(Event.COMPLETE, loadConfiguration);
  56. loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, loadConfiguration);
  57. loader.removeEventListener(IOErrorEvent.IO_ERROR, loadConfiguration);
  58. if (loader.xml != null)
  59. {
  60. xmlDeserializer.deserialize(loader.xml);
  61. }
  62. flashvarsDeserializer.deserialize(parameters);
  63. dispatchEvent(new Event(Event.COMPLETE));
  64. }
  65. loader.load(configurationContent);
  66. }
  67. // else {load content directly}
  68. }
  69. else
  70. {
  71. flashvarsDeserializer.deserialize(parameters);
  72. dispatchEvent(new Event(Event.COMPLETE));
  73. }
  74. }
  75. // Internals
  76. //
  77. private var xmlDeserializer:ConfigurationXMLDeserializer;
  78. private var flashvarsDeserializer:ConfigurationFlashvarsDeserializer;
  79. }
  80. }