Quoting "Mendelsohn, Michael" <[EMAIL PROTECTED]>:

Hi list...

Why is it that when I try to init a prop for my class, I get this error:
"A class's instance variables may only be initialized to compile-time
constant expressions."
What exactly does that mean?

class test{
        private var tf:TextFormat = new TextFormat();
        function test(){
                trace("hello");
        }
}

"new TextFormat()" is not a constant expression, like "null" or "3" or "Math.PI"
or "2 * Math.PI" or "'string text'". Each time you use those expressions it
evaluates to the same value, but each time you use "new TextFormat()" it
creates a new object. You have to instantiate nonconstant fields in the
constructor:

class Test {
        private var _tf:TextFormat;
        public function Test(){
               super();
               _tf = new TextFormat();
                trace("hello");
        }
}

(The "super();" is not strictly necessary; I'm just anal.)
--
Mike Keesey

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to