apache-flexmxmlflex4mxmlcgumbo

Why is the compiler complaining about a possibly undefined property


I have a very simple practice program for Flex 4 ( Gumbo ).

package
{
    import mx.controls.ColorPicker;
    import mx.controls.Label;
    import mx.events.ColorPickerEvent;
    import flash.display.Sprite;

    public class testClass extends Sprite
    {
       private var cPicker:ColorPicker = new ColorPicker();
       private var lbl:Label;

        public function testClass()
        {
            cPicker.addEventListener(ColorPickerEvent.CHANGE,
                colorPicker_change);
            cPicker.move(10, 10);
            addChild(cPicker);

            lbl = new Label();
            lbl.text = cPicker.hexValue;
            lbl.move(10, 40);
            addChild(lbl);
        }

        private function colorPicker_change(evt:ColorPickerEvent):void
        {
            lbl.text = cPicker.hexValue; // ff0000
        }
    }
}

But after building with 'mxmlc.exe testClass.as' on the command line, I get...

C:\src>mxmlc testClass.as Loading configuration file C:\flex_sdk_4\frameworks\flex-config.xml C:\src\testClass.as(21): col: 32 Error: Access of possibly undefined pro perty hexValue through a reference with static type mx.controls:ColorPicker.

        lbl.text = cPicker.hexValue;
                           ^ 

C:\src\testClass.as(28): col: 32 Error: Access of possibly undefined pro perty hexValue through a reference with static type mx.controls:ColorPicker.

        lbl.text = cPicker.hexValue; // ff0000
                           ^

Why does it think that cPicker is static? Or that cPicker.hexValue is undefined?

Also it seems that even after importing the ColorPicker library in the code using the import keyword, I somehow have to import it on the commandline for building as well. Is that correct?


Solution

  • According to my reading of the documentation hexValue isn't a property available on the ColorPicker. Do you mean selectedColor?