Hi All,
This is my first posting to this forum.
I have taken my first newbie steps to creating a stand-alone AS3
Application and have come across something I cannot understand. I
have an Application, and add an Image to it and it is fine. I add a
Button to it and it blows up with the AS3 equivalent of a null
pointer exception. The code is below. The error is below that. If I
comment out the line that does the "addChild(button)" it correctly
adds and displays the Image. What am I doing wrong? What is wrong
with how I am adding a button? Both Button and Image descend from
UIComponent.
package {
import mx.core.*;
import mx.events.*;
import mx.skins.halo.*;
import mx.styles.*;
import mx.controls.*;
import flash.display.*;
public class FirstApp extends Application
{
[Embed(source="connected_multiple_big.jpg")]
private var ImageClass:Class;
public function FirstApp()
{
super();
this.layout = "vertical";
this.setStyle("borderSkin",mx.skins.halo.HaloBorder);
this.addEventListener(FlexEvent.APPLICATION_COMPLETE, doInit);
}
private function doInit(e:FlexEvent):void {
var img:Image = new Image();
img.setStyle("verticalAlign","top");
img.source = ImageClass;
addChild(img);
// the troublesome test button. addChild() here causes a null object
reference exception
var button:Button = new Button();
button.label = "label";
addChild(button);
}
}
}
/// ****************************
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
at mx.core::UIComponent/getStyle()
at
mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewS
kinForPhase()
at
mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewS
kin()
at mx.controls::Button/mx.controls:Button::commitProperties()
at mx.core::UIComponent/validateProperties()
at mx.managers::LayoutManager/::validateProperties()
at mx.managers::LayoutManager/::doPhasedInstantiation()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/::callLaterDispatcher2()
at mx.core::UIComponent/::callLaterDispatcher()
at
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE
ventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.managers::SystemManager/::preloader_preloaderDoneHandler()
at
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE
ventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/::displayClassCompleteHandler()
at
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE
ventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::DownloadProgressBar/::timerHandler()
at mx.preloaders::DownloadProgressBar/::initCompleteHandler()
at
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE
ventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/::dispatchAppEndEvent()
at mx.preloaders::Preloader/::appCreationCompleteHandler()
at
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE
ventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/::doPhasedInstantiation()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/::callLaterDispatcher2()
at mx.core::UIComponent/::callLaterDispatcher()