Getting 'null object ref' error on trying to add a label to a Box
Hi,
I'm using Flash Builder 4 to create an action script based component. I've just started and the code right now is very simple - I have a class which extends the Box class. I set the width & height in the constructor and call an init() method where i create a label, add it using this.addChild(). When I run this I get the error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.styles::StyleManager$/getStyleManager()
at mx.styles::StyleProtoChain$/getStyleManager()
at mx.styles::StyleProtoChain$/initProtoChain()
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::initProtoChain()
at mx.core::UIComponent/regenerateStyleCache()
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild()
at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()
at mx.core::Container/addChildAt()
at mx.core::Container/addChild()
at component::Carousel/init()
at component::Carousel()
It errors out on line 125 of StyleManager.as
var styleManager:IStyleManager2 = IStyleManager2(moduleFactory.getImplementation("mx.styles::IStyleManager2"));
The code just preceding this line is
if (!moduleFactory)
{
moduleFactory = SystemManagerGlobals.topLevelSystemManagers[0];
// trace("no style manager specified, using top-level style manager");
}
Here's the code so far:
package component
{
import flash.events.Event;
import mx.containers.Box;
import mx.controls.Label;
public class Carousel extends Box
{
public function Carousel()
{
super();
this.direction = "Horizontal";
this.width = 100;
this.height = 100;
init();
} // End of public function Carousel
protected function init():void
{
var lb:Label = new Label();
lb.text = "heloo";
this.addChild(lb);
}
} // End of public class Carousel
} // End of package component
Any suggestions???
Thanks
Kunal
