A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Events not bubbling, not sure why

  1. #1
    Senior Member
    Join Date
    Jun 2004
    Posts
    193

    Events not bubbling, not sure why

    Hi,

    I'm messing about with an achievements system and I've run into some trouble with my event bubbling from game to achievements controller.

    3 important files, AchievementsController, GameController and Obj

    Gamecontroller is passed to achievements controller upon creation.

    Code:
    var game:GameController = new GameController();
    var achievementsController:AchievementsController = new AchievementsController(game);
    game.start();
    When game.start() is called, it creates an Obj and that then dispatches an event. That 'new obj' trace is being called, but the event isn't showing up.

    Code:
    package
    {
    	import flash.events.*;
    	public class Obj extends EventDispatcher
    	{
    		public function Obj()
    		{
    			trace("New 'Obj'");
    			dispatchEvent(new Event(Achievement.ACHIEVEMENT_EVENT,true));
    		}
    
    	}
    }
    And the achievements controller watches for that event, but it doesn't seem to be working.

    Code:
    package
    {
    	import flash.events.*;
    	public class AchievementsController
    	{
    		
    		private var game:GameController;
    		public function AchievementsController(_game:GameController)
    		{
    			game = _game;
    			game.addEventListener(Achievement.ACHIEVEMENT_EVENT, printAchievement);
    			trace("in ACH controller, listener added")
    		}
    		
    		private function printAchievement(e:Event):void
    		{
    			trace(e);
    		}
    
    	}
    }
    I can't seem to work out how to enable the event to bubble up through the gameController so that it can be picked up by the AchievementsController...

    Any Tips?

    Thanks,
    Alex

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Bubbling only works through the displayList. If obj is not a display child of the GameController, the even will have nowhere to bubble to. In fact, it will have nowhere to bubble to because you're dispatching the event in the constructor, before anything (other than itself) could possibly be listening.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center