Guest User

Untitled

a guest
Jun 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. /**
  2. * Dispatched when the config file has been loaded.
  3. */
  4. [Event (name="configurationLoaded", type="flash.events.Event")]
  5.  
  6. /**
  7. * Dispatched when the config file has been loaded.
  8. */
  9. [Event (name="configurationLoadFailed", type="flash.events.Event")]
  10.  
  11. public class ConfigurationData extends EventDispatcher{
  12. // Event name constants.
  13. public static const CONFIGURATION_LOADED:String = "configurationLoaded";
  14. public static const CONFIGURATION_LOAD_FAILED:String = "configurationLoadFailed";
  15.  
  16. // The singleton instance.
  17. private static var singleton:ConfigurationData;
  18.  
  19. /**
  20. * Don't call the constructor directly, use getInstance() instead.
  21. */
  22. public function ConfigurationData(pvt:PrivateClass){
  23. // init
  24. }
  25.  
  26. /**
  27. * Get the singleton ConfigurationData.
  28. * @return The ConfigurationData instance.
  29. */
  30. public static function getInstance():ConfigurationData{
  31. if ( !ConfigurationData.singleton ) ConfigurationData.singleton = new ConfigurationData(new PrivateClass());
  32. return ConfigurationData.singleton;
  33. }
  34.  
  35. public function initialize():void{
  36. var configureService:HTTPService = new HTTPService;
  37. configureService.url = _config_base_url + _config_path;
  38. configureService.addEventListener(FaultEvent.FAULT, onConfigureFault);
  39. configureService.addEventListener(ResultEvent.RESULT, onConfigureResult);
  40. configureService.send();
  41. }
  42.  
  43. private function onConfigureResult(event:ResultEvent):void{
  44. var i:int = 0;
  45. for(i=0; i<event.result.carriers.carrier.length; i++){
  46. _mobile_carriers.addItem({label:event.result.carriers.carrier[i].name, data:event.result.carriers.carrier[i].id});
  47. }
  48. dispatchEvent(new Event(CONFIGURATION_LOADED));
  49. }
  50.  
  51. private function onConfigureFault(event:FaultEvent):void{
  52. _mobile_carriers = _default_carriers as ArrayCollection;
  53. dispatchEvent(new Event(CONFIGURATION_LOAD_FAILED));
  54. }
  55. }
  56.  
  57. // This class is used to ensure that the ConfigurationData constructor can't be called directly,
  58. // getInstance() must be used instead.
  59. class PrivateClass {
  60. public function PrivateClass() {}
  61. }
  62.  
  63. ConfigurationData.getInstance().addEventListener(Event.CONFIGURATION_LOADED, onConfigurationLoaded);
  64.  
  65. public class ConfigurationEvent extends Event
  66. {
  67. public static const CONFIGURATION_LOADED:String = "configurationLoaded";
  68. public static const CONFIGURATION_LOAD_FAILED:String = "configurationLoadFailed";
  69.  
  70. public function ConfigurationEvent(type:String)
  71. {
  72. super(type);
  73. }
  74. }
  75.  
  76. dispatchEvent(new ConfigurationEvent(ConfigurationEvent.CONFIGURATION_LOAD_FAILED));
  77.  
  78. ConfigurationData.getInstance().addEventListener(ConfigurationEvent.CONFIGURATION_LOADED, onConfigurationLoaded);
Add Comment
Please, Sign In to add comment