Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to use the Level Manager (Citrus Engine recipe)
//In your Main class :
public function Main() {
levelManager = new LevelManager(ALevel);
levelManager.applicationDomain = ApplicationDomain.currentDomain; // to be able to load your SWF level on iOS
levelManager.levels = [[Level1, "levels/A1/LevelA1.swf"], [Level2, "levels/A2/LevelA2.swf"]];
levelManager.gotoLevel(); //load the first level, you can change the index. You can also call it later.
private function _onLevelChanged(lvl:ALevel):void {
state = lvl;
private function _nextLevel():void {
private function _restartLevel():void {
state = levelManager.currentLevel as IState;
// Note that you must create an abstract class : Level1 and Level2 extends ALevel
// which extends the State or StarlingState class. From our example :
public class ALevel extends State {
public var lvlEnded:Signal;
public var restartLevel:Signal;
protected var _level:MovieClip;
public function ALevel(level:MovieClip = null) {
_level = level;
lvlEnded = new Signal();
restartLevel = new Signal();
// Useful for not forgetting to import object from the Level Editor
var objectsUsed:Array = [Hero, Platform, Enemy, Sensor, CitrusSprite];
override public function initialize():void {
var box2d:Box2D = new Box2D("Box2D");
// create objects from our level made with Flash Pro

This comment has been minimized.

Copy link

@feresr feresr commented Sep 27, 2014

Thanks for this!, I see you've not called the 'setupStarling()' method, is that ok?


This comment has been minimized.

Copy link
Owner Author

@alamboley alamboley commented Nov 2, 2014

Here I'm using State, not StarlingState so we're on the display list ;)


This comment has been minimized.

Copy link

@keops232000 keops232000 commented Nov 5, 2014

Hy there i am a new flash builder developer.
I have a little question..can you put a link of how to make an import from flash pro to builder to a level made in flash pro? Or some tutorials to create levels in flash pro and use in builder



This comment has been minimized.

Copy link

@prmichaelsen prmichaelsen commented Nov 15, 2015

Critically important for anyone targeting Starling (just spent four hours trying to workaround a missing Starling context because I didn't understand the nature of my problem): your ALevel should extend StarlingState, not State. You will still need to call setUpStarling in your main. Like this:

public class ALevel extends StarlingState { ... }
public class Main extends StarlingCitrusEngine { 
    public function Main() {

Hopefully this will save you the headache I just dealt with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment