views:

124

answers:

3

I am new to AS3. When learning AS3, I get the below code from adobe example and try to run it giving a error like

 "1037: Packages cannot be nested."

What is this mean?

Please tell me how to execute? or any problem in this code?

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class TextField_alwaysShowSelection extends Sprite {
        public function TextField_alwaysShowSelection() {
            var label1:TextField = createTextField(0, 20, 200, 20);
            label1.text = "This text is selected.";
            label1.setSelection(0, 9);
            label1.alwaysShowSelection = true;

            var label2:TextField = createTextField(0, 50, 200, 20);
            label2.text = "Drag to select some of this text.";
        }

        private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x; result.y = y;
            result.width = width; result.height = height;
            addChild(result);
            return result;
        }
    }
}
A: 

Your code should compile, provided that it is in the root source folder ("src" in flex builder). Are you sure that's the entire file?

The error means that you have nested a package {} statement inside another package {} statement.

Richard Szalay
A: 

How are you running this file? This is not a complete file. If you are working with flex then you need the supported MXML code. However the error indicates that you are working with src folder. It would be good if you give the complete procedure.

A: 

If you are using Flash, put that code in a file named "TextField_alwaysShowSelection.as", place it next to your FLA and set that class name as the DocumentClass in the "properties" panel of your FLA... so where it says "Class:" write "TextField_alwaysShowSelection".

Cay