dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Movie with document class inside another movie

  1. #1
    Senior Member
    Join Date
    Nov 2005
    Location
    Milan
    Posts
    119

    resolved [RESOLVED] Movie with document class inside another movie

    Hi,

    I've got a movie with a main document class which controls all the other classes used in the movie. As I need to add a scrollbar which will scroll the entire movie I thought the easiest way would be to create a container movie, put the scrollbar in that and load my main movie into that. However, it generates a ton of errors.

    I think the problem is possibly related to the fact that the MainClass passes references to itself to the other classes in the movie and something's going wrong because it's no longer the top-level timeline. I'm not sure though. Here's an excerpt from my MainClass:

    PHP Code:
    public function MainClass() {
            
    _instance this;
            
    _firstPage true;
            
    menu3D = new Menu3D();
            
    navigate = new Navigate();
            
    animationManager = new AnimationManager();
            
    sectionLoader = new SectionLoader();
            
    mainMenu = new MainMenu();
            
    backMenu = new BackMenu();
    }
            
    public static function 
    getInstance():MainClass 
            return 
    _instance
    }
    public static function 
    getStage():Stage 
            return 
    getInstance().stage

    Any thoughts?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yep. If MainClass is no longer the document class, then the stage property will be null until it is put on the displaylist. If anything created in the constructor (or functions called as a result of that) depends on the stage returned from getStage, then there will be errors caused by the null stage. Delay the initialization until the MainClass instance is on the stage.
    Code:
    public function MainClass(){
      addEventListener(Event.ADDED_TO_STAGE, init);
    }
    
    private function init(event:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            _instance = this;
            _firstPage = true;
            menu3D = new Menu3D();
            navigate = new Navigate();
            animationManager = new AnimationManager();
            sectionLoader = new SectionLoader();
            mainMenu = new MainMenu();
            backMenu = new BackMenu();
    }
            
    public static function getInstance():MainClass {
            return _instance;
    }
    public static function getStage():Stage {
            return getInstance().stage;
    }

  3. #3
    Senior Member
    Join Date
    Nov 2005
    Location
    Milan
    Posts
    119
    Brilliant, that's exactly what I was looking for. Thanks a million.

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