public
Created

Lisntening for events

  • Download Gist
GV.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package
{
import blocked.events.NewWorldEvent;
import blocked.worlds.World;
import blocked.worlds.WorldManager;
import net.hires.debug.Stats;
import playerio.Client;
import playerio.Connection;
import starling.core.Starling;
import starling.display.Sprite;
import starling.events.EventDispatcher;
/**
* ...
* @author Raimonds Zarins
*/
public class GV
{
public static var gameFramework:Starling;
public static var fpsStats:Stats;
public static var currentClient:Client;
public static var currentConnection:Connection;
public static var userName:String;
public static var userID:String;
public static var currentWorld:World = null;
public static var worldManager:WorldManager;
}
 
}
Game.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
package
{
import blocked.events.NewWorldEvent;
import blocked.worlds.Lobby;
import blocked.worlds.World;
import blocked.worlds.WorldManager;
import feathers.controls.Button;
import feathers.controls.Callout;
import feathers.controls.Label;
import feathers.themes.AeonDesktopTheme;
import starling.events.Event;
import starling.display.Sprite;
/**
* ...
* @author Raimonds Zarins
*/
public class Game extends Sprite
{
public function Game()
{
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
trace("Starling running");
GV.worldManager = new WorldManager();
this.addChild(GV.worldManager);
GV.worldManager.setWorld(new Lobby());
GV.worldManager.addEventListener(NewWorldEvent.CHANGE, addToStage);
}
private function addToStage(e:NewWorldEvent):void
{
this.addChild(e.world as World);
trace("Handling new world event!");
}
 
}
 
}
NewWorldEvent.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
package blocked.events
{
import blocked.worlds.World;
import starling.events.Event;
/**
* ...
* @author Raimonds Zarins
*/
public class NewWorldEvent extends Event
{
public static const CHANGE:String = "WorldChange";
private var rWorld:World;
public function NewWorldEvent(type:String, result:World, bubbles:Boolean=false)
{
super(type, bubbles);
this.rWorld = result;
trace("Dispatching NewWorldEvent!");
}
public function get world():World { return this.rWorld; }
}
 
}
WorldManager.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package blocked.worlds
{
import blocked.events.NewWorldEvent;
import starling.display.Sprite;
import starling.events.EventDispatcher;
/**
* ...
* @author Raimonds Zarins
*/
public class WorldManager extends Sprite
{
public function WorldManager()
{
}
public function setWorld(world:World):void
{
trace("Changing world");
if(GV.currentWorld != null)
GV.currentWorld.unloadWorld();
GV.currentWorld = world;
dispatchEvent(new NewWorldEvent(NewWorldEvent.CHANGE, world));
if(GV.currentWorld.loaded)
GV.currentWorld.loadWorld();
}
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.