[ascoders] Re: Static Classes an ASBroadcaster initialisieren


Hier ein Dummy. Die Methode findPath wird aus der Timeline aufgerufen.
"broadcastMessage" funktioniert natürlich nicht, weil der AsBroadcaster
nicht initialisiert ist. Dafür sollte es doch eine Lösung geben ?

ach so, du willst Agent als Broadcaster haben, nicht PathFinder?! Warum?


Der Dummy würde wenn mich nicht alles täuscht analog dazu so aussehen:

_____________________________________________________________

class Agent
{
        /*
                Agent als Broadcaster
        */
        private static var b = AsBroadcaster.initialize(Agent);

        /*
                die statische Broadcaster-Methoden
                (oder auch über extends AsBroadcaster ...)
        */
        private static function broadcastMessage() {}

private static function addListener() {}

private static function removeListener() {}

        /*
                Zähler für die IDs
        */
        private static var agentCount:Number = 0;

private var agentId:Number;

        /*
                create and move
        */
        public static function findPath()
        {
                new Agent();
        }

        private function Agent()
        {
                agentId = agentCount++;
                trace("Agent 00" + agentId + " created.");
                trace("--------------------------------");
                Agent.addListener(this);
                Agent.broadcastMessage("move");
                trace("--------------------------------");
        }

        private function move()
        {
                trace("Agent 00" + agentId + " is moving.");
        }
}

_____________________________________________________________

Test, Tesst, Tsst ...
_____________________________________________________________

Agent.findPath();
Agent.findPath();
Agent.findPath();
Agent.findPath();

_____________________________________________________________

Output, putt, puttt ....
_____________________________________________________________

Agent 000 created.
--------------------------------
Agent 000 is moving.
--------------------------------
Agent 001 created.
--------------------------------
Agent 000 is moving.
Agent 001 is moving.
--------------------------------
Agent 002 created.
--------------------------------
Agent 000 is moving.
Agent 001 is moving.
Agent 002 is moving.
--------------------------------
Agent 003 created.
--------------------------------
Agent 000 is moving.
Agent 001 is moving.
Agent 002 is moving.
Agent 003 is moving.
--------------------------------

___________________________________________________________

ralf ...


------------------------------------------------------ Archiv : http://www.freelists.org/archives/ascoders/ Optionen : http://www.freelists.org/list/ascoders ------------------------------------------------------

Other related posts: