Class initialization is just a bunch of code.  The eye class may not be
fully setup by the time customIcons is getting initialized.

 

When it is an instance var, the eye class has probably been fully setup
by instantiation time.

 

Assigning default values to statics that are not compile-time constants
is "dangerous"

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Pan Troglodytes
Sent: Friday, July 25, 2008 10:05 AM
To: flexcoders
Subject: [flexcoders] problem with embeds in static variables

 

I'm confused as to why the following gets a runtime error:

package nes
{
  import mx.collections.ArrayCollection;

  public class WATIcons
  {

    [Embed(source="/assets/customIcons/eye-16x16--CCFFF.png")] public
static var eye:Class;
    public static var customIcons:ArrayCollection = new
ArrayCollection([eye]);
  }
}

TypeError: Error #1009: Cannot access a property or method of a null
object reference.
    at nes::WATIcons$/get eye()[C:\Documents and Settings\xxxxxxxx\My
Documents\Flex Builder 3\WATControl\nes\WATIcons.as:70]
    at nes::WATIcons$cinit()

Yet if I remove the static and create an instance of the class, I don't
get any errors.  I can then use the customIcons array element 0 just
fine.  I'd really rather have them as static, as they are used all over
in the application.  Is there some way around this, or is it
unavoidable?  If it's unavoidable, then just out of curiosity what is
causing the problem for the compiler?

-- 
Jason 

 

Reply via email to