4 Replies Latest reply on Oct 8, 2009 12:44 AM by LarrySpace

    I cannot import to use another .as file

    LarrySpace

      Hello to all…

      I am new in Flex builder (3) and in action script general… The problem I have that I cannot import to use another .as file. Here we are…

      The error message:

      1046: Type was not found or was not a compile-time constant: RotatedButton.  AnActionScriptApp1/src                AnActionScriptApp1.as  line 10   1254854759640  486

       

       

      Please read the attached doc where contains some screenshots.

       

       

      Thank you,

      Larry

        • 1. Re: I cannot import to use another .as file
          Gregory Lafrance Level 6

          Can't open attached zip file, error says it is corrupt.

           

          Are doing this:

           

          import path1.path2.RotatedButton;

           

          or

           

          include "path1/path2/RotatedButton.as";

           

          If this post answered your question or helped, please mark it as such.

          • 2. Re: I cannot import to use another .as file
            LarrySpace Level 1

            ok, I send all info included in the attachment...

             

             

            Hello to all…

            I am new in Flex builder (3) and in action script general… The problem I have that I cannot import to use another .as file. Here we are…

             

            The main AnActionScriptApp1.as code where tries to call the RotatedButton class

             

            src\com\company\UserComponents\Rotated.as file: (the "utility" file/package) (blue is the interesting class)
            package com.company.UserComponents {
              import flash.display.Sprite;
              public class RotatedButton extends Sprite {
                public function RotatedButton() {
                  var button:Button; rotationValue=0;
                  public function RotatedButton(){
                    Button = new Button(this);
                    button.x=100;button.y=100;
                    AddChild(button);
                    addEventListener(Event.ENTER_FRAME, RotateThisThing);
                  }
                  private function RotateThisThing(e:Event): void {
                    rotationValue+=1;
                  button.rotation=rotationValue;
                  }
                }
              }
              public class RotatedComboBox extends Sprite {
                var combobox:
                public function RotatedComboBox() {
                  super();
                }
              }
            }

            src\AnActionScriptApp1.as file: (the launch application file)

            package {

              import com.company.UserComponents.RotatedButton;

              import flash.display.Sprite;

              public class AnActionScriptApp1 extends Sprite{

                public function AnActionScriptApp1(){

                 var rb : RotatedButton = new RotatedButton();

                 addChild(rb);

                }

              }

            }

             

            The red indicated lines are lines with compiler error messages.

            1st line's error message:

            1046: Type was not found or was not a compile-time constant: RotatedButton.  AnActionScriptApp1/src                AnActionScriptApp1.as  line 10  1254854759640  486


            BUT, when I press the F3 on RotateButton text of “import” line or of “var” line, the Flex builder is finding the declaration correctly in the Rotated.as… so… where this error?

             

            To be honest… this example really doesn’t meet the reality as we never rotate the buttons… by the way...

             

            Kind regards

            Larry

            • 3. Re: I cannot import to use another .as file
              Gregory Lafrance Level 6

              You may need to define the instance of the RotatedButton outside the function so it exists outside it.

               

              If this post answers your question or helps, please mark it as such.

               

              public class AnActionScriptApp1 extends Sprite{

                 public var rb:RotatedButton;

                  public function AnActionScriptApp1(){

                   rb = new RotatedButton();

                   addChild(rb);

                  }

                }

              • 4. Re: I cannot import to use another .as file
                LarrySpace Level 1

                The problem solved when I renamed the .as file with the name of the class! Is this a syntax rule?

                 

                So a “fundamental” question came to my mind….

                May I have more than one classes in a package file??? Or for each one class I have to create another file? When a add more than one public classes in the same package file I get the follow error.

                “A file found in a source-path can not have more than one externally visible definition. com.company.UserComponents:RotatedButton;com.company.UserComponents:RotatedComboBox”

                 

                 

                Now, something else, compiler returns me the follow error… what does it means… and what I have to do?

                "Severity and Description Path Resource Location Creation Time Id

                Unable to resolve resource bundle "core" for locale "en_US". AnActionScriptApp2 Unknown 1254987213156 629

                Unable to resolve resource bundle "core" for locale "en_US". AnActionScriptApp2 Unknown 1254987213156 630

                Unable to resolve resource bundle "core" for locale "en_US". AnActionScriptApp2 Unknown 1254987213156 632

                Unable to resolve resource bundle "effects" for locale "en_US". AnActionScriptApp2 Unknown 1254987213156 631

                Unable to resolve resource bundle "skins" for locale "en_US". AnActionScriptApp2 Unknown 1254987213156 628

                Unable to resolve resource bundle "styles" for locale "en_US". AnActionScriptApp2 Unknown 1254987213156 633

                1084: var 'rotationValue' will be scoped to the default namespace: RotatedButton: internal.  It will not be visible outside of this package. AnActionScriptApp2/src/com/company/UserComponents RotatedButton.as line 10 1254987213125 627"

                Kind regards
                Larry