views:

408

answers:

1

I have a class that I instantiate at creation complete:

public var catalog : AppCollection = new AppCollection (catalogStrip);

CatalogStrip is an HBox.

In this class, I create a VBox and add it as a child to catalogStrip. Here is the constructor for said class:

public function AppCollection (_container : HBox) {
    this.container = _container;
}

And here is the code I'm having trouble with:

public function populate (e : ResultEvent) : void {
    var appImage : Image = new Image ();
    var appText : Text = new Text ();
    var appContainer : VBox = new VBox ();

    appImage.source = "./res/Halo.png";
    appImage.width = 70;
    appImage.height = 70;

    appText.text = "Halo 4";

    appContainer.width = 110;
    appContainer.height = 125;
    appContainer.addChild (appImage);
    appContainer.addChild (appText);

    tbox = appContainer;

    this.container.addChild (appContainer);
}

On the last line, it says that this.container is null. Impossible! I added it in the constructor! Furthermore, I also tried instantiating main.mxml and accessing the container from there. When I try the same code from a script tag in main.mxml, it works, but that kills the whole point of having the class there in the first place. How can I access MXML tags from an external class? I have all my imports and everything...

+1  A: 
public var catalog : AppCollection = new AppCollection (catalogStrip);

Is the in the script portion of the main.mxml? If so, it is the reason you are getting a null object. You need to have a method:

public var catalog : AppCollection;

private function handleCreationComplete():void
{
    this.catalog = new AppCollection(catalogStrip);
}
Joel Hooks