Created
March 13, 2010 20:37
-
-
Save alecmce/331534 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.text.TextField; | |
public class EnterFrameIsConfusing extends Sprite | |
{ | |
private var output:TextField; | |
private var a:EnterFrameListenerA; | |
private var b:EnterFrameListenerB; | |
private var frameCount:int = 0; | |
public function EnterFrameIsConfusing() | |
{ | |
output = new TextField(); | |
output.width = stage.stageWidth; | |
output.height = stage.stageHeight; | |
addChild(output); | |
addEventListener(Event.ENTER_FRAME, onEnterFrame); | |
a = new EnterFrameListenerA(output); | |
a.addListeners(); | |
b = new EnterFrameListenerB(output); | |
b.addListeners(); | |
} | |
private function onEnterFrame(event:Event):void | |
{ | |
switch (frameCount) | |
{ | |
case 1: | |
a.removeListeners(); | |
break; | |
case 2: | |
a.addListeners(); | |
break; | |
case 4: | |
b.addChild(a); | |
break; | |
case 6: | |
b.removeChild(a); | |
a.addChild(b); | |
break; | |
case 8: | |
a.removeListeners(); | |
b.removeListeners(); | |
removeEventListener(Event.ENTER_FRAME, onEnterFrame); | |
break; | |
} | |
output.appendText("frame" + (frameCount++) + "\n"); | |
} | |
} | |
} | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.text.TextField; | |
internal class EnterFrameListenerA extends Sprite | |
{ | |
private var output:TextField; | |
public function EnterFrameListenerA(output:TextField) | |
{ | |
this.output = output; | |
} | |
public function addListeners():void | |
{ | |
addEventListener(Event.ENTER_FRAME, lowPriority, false, 0); | |
addEventListener(Event.ENTER_FRAME, highPriority, false, 100); | |
} | |
public function removeListeners():void | |
{ | |
removeEventListener(Event.ENTER_FRAME, highPriority); | |
removeEventListener(Event.ENTER_FRAME, lowPriority); | |
} | |
private function lowPriority(event:Event):void | |
{ | |
output.appendText("A (0)\n"); | |
} | |
private function highPriority(event:Event):void | |
{ | |
output.appendText("A (100)\n"); | |
} | |
} | |
internal class EnterFrameListenerB extends Sprite | |
{ | |
private var output:TextField; | |
public function EnterFrameListenerB(output:TextField) | |
{ | |
this.output = output; | |
} | |
public function addListeners():void | |
{ | |
addEventListener(Event.ENTER_FRAME, lowPriority, false, -100); | |
addEventListener(Event.ENTER_FRAME, highPriority, false, 20); | |
} | |
public function removeListeners():void | |
{ | |
removeEventListener(Event.ENTER_FRAME, highPriority); | |
removeEventListener(Event.ENTER_FRAME, lowPriority); | |
} | |
private function lowPriority(event:Event):void | |
{ | |
output.appendText("B (-100)\n"); | |
} | |
private function highPriority(event:Event):void | |
{ | |
output.appendText("B (20)\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment