Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 19th, 2018 53 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. package
  2. {
  3.     import flash.display.DisplayObject;
  4.     import flash.display.DisplayObjectContainer;
  5.     import flash.display.Sprite;
  6.     import flash.display.Stage;
  7.     import flash.display.StageAlign;
  8.     import flash.events.ErrorEvent;
  9.     import flash.events.Event;
  10.     import flash.events.UncaughtErrorEvent;
  11.     import flash.utils.setTimeout;
  12.  
  13.     public class TestFakeStage extends Sprite
  14.     {
  15.         private var fakeStage:Sprite;
  16.  
  17.         private var s:Array;
  18.  
  19.         private var _errorsOcccurred:int = 0;
  20.  
  21.         public function TestFakeStage()
  22.         {
  23.             loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
  24.  
  25.             fakeStage = new Sprite();
  26.             fakeStage.name = "fakeStage";
  27.             fakeStage.addEventListener(Event.ADDED, addedHandler);
  28.  
  29.             // generate real event sequence
  30.             generateEvents(stage);
  31.  
  32.             trace("");
  33.             // generate fake event sequence
  34.             generateEvents(fakeStage);
  35.  
  36.         }
  37.  
  38.         private function generateEvents(r:DisplayObjectContainer):void
  39.         {
  40.             s = [];
  41.             trace("Generating event sequence...");
  42.             trace("=====================================================");
  43.  
  44.             createSprite("a1");
  45.             s["a1"].addChild(createSprite("a2"));
  46.             r.addChild(s["a1"]);
  47.  
  48.             s["a1"].addChild(createSprite("a3"));
  49.  
  50.             r.addChild(createSprite("b1"));
  51.             s["b1"].addChild(createSprite("b2"));
  52.         }
  53.  
  54.         private function createSprite(sprName:String):Sprite
  55.         {
  56.             var spr:Sprite = s[sprName] = new Sprite();
  57.  
  58.             spr.name = sprName;
  59.             spr.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
  60.  
  61.             return spr;
  62.         }
  63.  
  64.         private function addedHandler(event:Event):void
  65.         {
  66.             // fire fake ADDED_TO_STAGE
  67.             if (event.target != fakeStage)
  68.             generateFakeEvent(event.target as DisplayObject);
  69.         }
  70.  
  71.         private function addedToStageHandler(event:Event):void
  72.         {
  73.             var cTarget:DisplayObject = event.currentTarget as DisplayObject;
  74.             var target:DisplayObject = event.target as DisplayObject;
  75.  
  76.             trace(cTarget.name + " reported: " + target.name + " added to Stage");
  77.         }
  78.  
  79.         private function generateFakeEvent(target:DisplayObject):void
  80.         {
  81.             target.dispatchEvent(new Event(Event.ADDED_TO_STAGE));
  82.  
  83.             if (target is DisplayObjectContainer)
  84.             {
  85.                 var cont:DisplayObjectContainer = target as DisplayObjectContainer;
  86.                 for (var i:int = 0; i < cont.numChildren; i++)
  87.                 {
  88.                     generateFakeEvent(cont.getChildAt(i));
  89.                 }
  90.             }
  91.         }
  92.  
  93.         private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
  94.         {
  95.             _errorsOcccurred++
  96.             if (event.error is Error)
  97.             {
  98.                 var error:Error = event.error as Error;
  99.             }
  100.             else if (event.error is ErrorEvent)
  101.             {
  102.                 var errorEvent:ErrorEvent = event.error as ErrorEvent;
  103.             }
  104.             else
  105.             {
  106.  
  107.             }
  108.         }
  109.     }
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top