> Any ideas anyone?

 

About what? My previous reply explained that an <mx:Application> in MXML
autogenerates CSS selector setup code that you don't get when you simply
subclass Application in AS3. That's why this works and your previous
code didn't. Turn on -keep-autogenerated-actionscript to see this code.

 

- Gordon

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Greg McCreath
Sent: Thursday, November 16, 2006 8:06 PM
To: [email protected]
Subject: RE: [flexcoders] Newbie: Why can't I add a button!

 

Thanks.

 

It works fine as a MXML app.  Here it is.  Any ideas anyone? .... 

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical" creationComplete="startMe()">

 

<mx:Script>

            <![CDATA[

             import mx.core.*;

             import mx.events.*;

             import mx.skins.halo.*;

             import mx.styles.*;

             import mx.controls.*;

             import flash.display.*;

 

              [Embed(source="connected_multiple_big.jpg")]

              private var ImageClass:Class;

               

                        public function startMe():void {

                           var img:Image = new Image();

                           img.setStyle("verticalAlign","top");

                           img.source = ImageClass;  

                           addChild(img);

   

                            var button:Button = new Button();

                            button.label = "label";

                            addChild(button);  

                        }

            ]]>

</mx:Script>

            

</mx:Application>

 

Greg McCreath
Chief Technical Officer
TAFMO Limited
ABN:  94 109 766 592

Level 8, 342 Flinders Street
Melbourne
Victoria, 3000
Australia

http://www.tafmo.com
Ph <http://www.tafmo.comPh>  : +61 (0) 3 9018 6824
Fax : +61 (0) 3 9018 6899
Mobile : +61 (0) 401 988 957

________________________________

From: Matt Chotin [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 November 2006 2:35 PM
To: [email protected]
Subject: RE: [flexcoders] Newbie: Why can't I add a button!

 

Looks like the style code may not be loading correctly.  What happens if
you use an MXML file for your application instead of AS?

 

Matt

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of bookymcnuggett
Sent: Thursday, November 16, 2006 5:49 PM
To: [email protected]
Subject: [flexcoders] Newbie: Why can't I add a button!

 

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
<http://www.adobe.com/2006/flex/mx/internal::viewS> 
kinForPhase()
at 
mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewS
<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
<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
<http://adobe.com/AS3/2006/builtin::apply> ()
at mx.core::UIComponent/::callLaterDispatcher2()
at mx.core::UIComponent/::callLaterDispatcher()

________________________________

This email and any files transmitted with it may be confidential and are
intended solely for the use of the individual or entity to whom they are
addressed. This email may contain personal information of individuals,
and be subject to Commonwealth and/or State privacy laws in Australia.
This email is also subject to copyright. If you are not the intended
recipient, you must not read, print, store, copy, forward or use this
email for any reason, in accordance with privacy and copyright laws. If
you have received this email in error, please notify the sender by
return email, and delete this email from your inbox. 

 

Reply via email to