Posted By

darkbaron1912 on 02/18/11


Tagged

loading LoaderContext


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dubogii
merritt212


loading


 / Published in: ActionScript 3
 

  1. var addedDefinitions : LoaderContext = new LoaderContext();
  2. addedDefinitions.applicationDomain = ApplicationDomain.currentDomain;
  3. var urlReq : URLRequest = new URLRequest(libary_swf);
  4. var loader : Loader= new Loader();
  5. loader.load(urlReq, addedDefinitions);
  6. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedGraphic);
  7. loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadUncomplete);
  8.  
  9. private function loadUncomplete(e:IOErrorEvent):void
  10. {
  11. sendNotification(GameFacade.ERRORGAME, "Error " +e.toString);
  12. }
  13.  
  14. private function loadedGraphic(e:Event):void
  15. {
  16.  
  17. sendNotification(GameFacade.LOADGRAPHIC) ;
  18. gameInit();
  19. }
  20.  
  21.  
  22.  
  23.  
  24. /// loading css
  25.  
  26.  
  27. package {
  28. import flash.display.Sprite;
  29. import flash.events.Event;
  30. import flash.net.URLLoader;
  31. import flash.net.URLRequest;
  32. import flash.text.StyleSheet;
  33. import flash.text.TextField;
  34. import flash.text.TextFieldAutoSize;
  35.  
  36. public class CSSFormattingExample extends Sprite {
  37. var loader:URLLoader;
  38. var field:TextField;
  39. var exampleText:String = "<h1>This is a headline</h1>" +
  40. "<p>This is a line of text. <span class='bluetext'>" +
  41. "This line of text is colored blue.</span></p>";
  42.  
  43. public function CSSFormattingExample():void {
  44. field = new TextField();
  45. field.width=300;
  46. field.autoSize=TextFieldAutoSize.LEFT;
  47. field.wordWrap=true;
  48. addChild(field);
  49.  
  50. var req:URLRequest=new URLRequest("example.css");
  51.  
  52. loader = new URLLoader();
  53. loader.addEventListener(Event.COMPLETE, onCSSFileLoaded);
  54. loader.load(req);
  55. }
  56.  
  57. public function onCSSFileLoaded(event:Event):void {
  58. var sheet:StyleSheet = new StyleSheet();
  59. sheet.parseCSS(loader.data);
  60. field.styleSheet=sheet;
  61. field.htmlText=exampleText;
  62. }
  63. }
  64. }
  65.  
  66.  
  67. // THE 'example.css' FILE SHOULD LOOK LIKE THIS ...
  68. //p {
  69. // font-family: Times New Roman, Times, _serif;
  70. // font-size: 14;
  71. //}
  72. //
  73. //h1 {
  74. // font-family: Arial, Helvetica, _sans;
  75. // font-size: 20;
  76. // font-weight: bold;
  77. //}
  78. //
  79. //.bluetext {
  80. // color: #0000CC;
  81. //}

Report this snippet  

You need to login to post a comment.