Removed MethodQueue.setStage(), use the same trick we use in
AnimationManager and that I saw in use in Tweener: just listen for ENTER_FRAME on some random sprite. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4926 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -55,7 +55,6 @@ public class Client extends EventDispatcher
|
|||||||
{
|
{
|
||||||
_creds = creds;
|
_creds = creds;
|
||||||
_stage = stage;
|
_stage = stage;
|
||||||
MethodQueue.setStage(stage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,9 +268,7 @@ public class Client extends EventDispatcher
|
|||||||
// we need to wait for the CLIENT_WILL_LOGON to have been dispatched before we actually
|
// we need to wait for the CLIENT_WILL_LOGON to have been dispatched before we actually
|
||||||
// tell the communicator to logon, so we run this through the callLater pipeline
|
// tell the communicator to logon, so we run this through the callLater pipeline
|
||||||
_comm = new Communicator(this);
|
_comm = new Communicator(this);
|
||||||
callLater(function () :void {
|
callLater(_comm.logon);
|
||||||
_comm.logon();
|
|
||||||
});
|
|
||||||
|
|
||||||
// it is safe, however, to start up our tick interval immediately
|
// it is safe, however, to start up our tick interval immediately
|
||||||
if (_tickInterval == null) {
|
if (_tickInterval == null) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
import flash.display.Stage;
|
import flash.display.Sprite;
|
||||||
|
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
|
|
||||||
@@ -31,48 +31,14 @@ import flash.events.Event;
|
|||||||
*/
|
*/
|
||||||
public class MethodQueue
|
public class MethodQueue
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Set the stage which will be used for coordinating the use of the
|
|
||||||
* method queue. If no stage is set, functions will continue to pile up
|
|
||||||
* without being called.
|
|
||||||
*/
|
|
||||||
public static function setStage (stage :Stage) :void
|
|
||||||
{
|
|
||||||
if (_listening) {
|
|
||||||
removeListener();
|
|
||||||
}
|
|
||||||
_stage = stage;
|
|
||||||
checkListen();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the specified method at the entry to the next frame.
|
* Call the specified method at the entry to the next frame.
|
||||||
*/
|
*/
|
||||||
public static function callLater (fn :Function, args :Array = null) :void
|
public static function callLater (fn :Function, args :Array = null) :void
|
||||||
{
|
{
|
||||||
_methodQueue.push([fn, args]);
|
_methodQueue.push([fn, args]);
|
||||||
if (!_listening) {
|
if (!_d.hasEventListener(Event.ENTER_FRAME)) {
|
||||||
checkListen();
|
_d.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop listening for the frame event.
|
|
||||||
*/
|
|
||||||
protected static function removeListener () :void
|
|
||||||
{
|
|
||||||
_stage.removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
|
|
||||||
_listening = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to see if we should be listening for the next frame event.
|
|
||||||
*/
|
|
||||||
protected static function checkListen () :void
|
|
||||||
{
|
|
||||||
if (_stage != null && _methodQueue.length > 0) {
|
|
||||||
_stage.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
|
|
||||||
_listening = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,17 +67,14 @@ public class MethodQueue
|
|||||||
// If no new functions were added while we were calling the current set,
|
// If no new functions were added while we were calling the current set,
|
||||||
// then remove the listener.
|
// then remove the listener.
|
||||||
if (_methodQueue.length == 0) {
|
if (_methodQueue.length == 0) {
|
||||||
removeListener();
|
_d.removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The stage we're working with. */
|
/** A display object on which we listen for ENTER_FRAME. */
|
||||||
protected static var _stage :Stage;
|
protected static var _d :Sprite = new Sprite();
|
||||||
|
|
||||||
/** The currently queued functions. */
|
/** The currently queued functions. */
|
||||||
protected static var _methodQueue :Array = [];
|
protected static var _methodQueue :Array = [];
|
||||||
|
|
||||||
/** Are we presently listening for the frame event? */
|
|
||||||
protected static var _listening :Boolean = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user