25 Replies Latest reply on May 20, 2009 4:47 PM by hsfrey

    Error: "Could not resolve [public class] to a component implementation

    hsfrey Level 1

      Here's another clueless newbie question! :-(

       

      I define a public class "DynamicTextArea" at the top of the file, and get the compiler error message "Could not resolve <DynamicTextArea> to a component implementation" at the bottom of the same file.

       

      Clearly, I don't understand something very basic.

       

      (The code between the commenrted asterisks was originally in a separate package file, which I couldn't get either mxmlc or FlexBuilder to find, so rather than fight that issue now, I moved it into the same file.)

       

      Here's the file:

       

      <?xml version="1.0" encoding="utf-8" ?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      >
      <!--****************************************************************-->
          <mx:Script>
          <![CDATA[
        import flash.events.Event;
        import mx.controls.TextArea;

      public class DynamicTextArea extends TextArea{
          public function DynamicTextArea(){
            super();
            super.horizontalScrollPolicy = "off";
            super.verticalScrollPolicy = "off";
            this.addEventListener(Event.CHANGE, adjustHeightHandler);
          }
          private function adjustHeightHandler(event:Event):void{
            trace("textField.getLineMetrics(0).height: " + textField.getLineMetrics(0).height);
            if(height <= textField.textHeight + textField.getLineMetrics(0).height){
              height = textField.textHeight;    
              validateNow();
            }
          }
          override public function set text(val:String):void{
            textField.text = val;
            validateNow();
            height = textField.textHeight;
            validateNow();
          }
          override public function set htmlText(val:String):void{
            textField.htmlText = val;
            validateNow();
            height = textField.textHeight;
            validateNow();
          }
          override public function set height(value:Number):void{
            if(textField == null){
              if(height <= value){
                super.height = value;
              }
            }else{      
              var currentHeight:uint = textField.textHeight + textField.getLineMetrics(0).height;
              if (currentHeight<= super.maxHeight){
                if(textField.textHeight != textField.getLineMetrics(0).height){
                  super.height = currentHeight;
                }       
              }else{
                  super.height = super.maxHeight;        
              } 
            }
          }
          override public function get text():String{
              return textField.text;
          }
          override public function get htmlText():String{
              return textField.htmlText;
          }
        
          override public function set maxHeight(value:Number):void{
            super.maxHeight = value;
          }
        }
          ]]>
        </mx:Script>
      <!--****************************************************************-->
           <mx:Script>
          <![CDATA[
            import mx.controls.Alert;
          
            private var str:String = "This text will be long enough to trigger " +
              "the TextArea to increase its height.";
            private var htmlStr:String = "This <b>text</b> will be <font color='#00FF00'>long enough</font> to trigger " +
              "the TextArea to increase its height.";
            private function setLargeText():void{
              txt1.text = str;
              txt2.text = str;
              txt3.text = str;
              txt4.text = str;
              txt5.htmlText = htmlStr;
              txt6.htmlText = htmlStr;
              txt7.htmlText = htmlStr;
              txt8.htmlText = htmlStr;
            }
          ]]>
        </mx:Script>
        <DynamicTextArea id="txt1" width="300" height="14"/>
        <DynamicTextArea id="txt2" width="300" height="20"/>
        <DynamicTextArea id="txt3" width="300" height="28"/>
        <DynamicTextArea id="txt4" width="300" height="50"/>
        <DynamicTextArea id="txt5" width="300" height="14"/>
        <DynamicTextArea id="txt6" width="300" height="20"/>
        <DynamicTextArea id="txt7" width="300" height="28"/>
        <DynamicTextArea id="txt8" width="300" height="50"/>
        <mx:Button label="Set Large Text" click="setLargeText();"/>
      </mx:Application>

       

           Thanks for any insight you can provide!

       

      Harvey

        • 1. Re: Error: "Could not resolve [public class] to a component implementation
          injpix Level 3

          You need to create a namespace in the Application tag.  For an example:

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                          xmlns:view="com.injectedpixels.flex.xiffmessenger.view.components.*"
                          xmlns:myCustomClass="*" >

               //...

               <myCustomClass:DynamicTextArea id="txt6" width="300" height="20"/>

               //...

          </mx:Application>

          • 2. Re: Error: "Could not resolve [public class] to a component implementation
            hsfrey Level 1

            myIP:

             

                 Thanks.

             

                 So I changed it to start:

             

            <?xml version="1.0" encoding="utf-8" ?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            xmlns:DTA="*"
            >
            <!--****************************************************************-->
                <mx:Script>
                <![CDATA[
              import flash.events.Event;
              import mx.controls.TextArea;

            package DTA{   // around the entire class
            public class DynamicTextArea extends TextArea{
                public function DynamicTextArea(){
            <snip>

              <DTA:DynamicTextArea id="txt1" width="300" height="14"/>

            <snip>

             

             

                 And now I get a compiler error saying that "package is unexpected".

             

            I guess I'm just used to C where if I declare something in the same file the compiler knows about it everywhere in that file.

             

            Harvey

            • 3. Re: Error: "Could not resolve [public class] to a component implementation
              Michael Borbor Level 4

              When you add this

               

              package DTA

               

              You're saying that your class is inside a folder DTA, if it's not then delete DTA and your class will be in the default package.

               

              Adding DTA to your class is not required.

              • 4. Re: Error: "Could not resolve [public class] to a component implementation
                injpix Level 3

                Closer.  If DynamicTextArea resides in a package of, "com.hsfrey.flexlib", you would instantiate it in the MXML code as below:

                 

                <!-- application.MXML -->

                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml

                                xmlns:myCustomClass="com.hsfrey.flexlib.*" >

                     //...

                     <myCustomClass:DynamicTextArea id="txt6" width="300" height="20"/>

                     //...

                </mx:Application>

                 

                /* com.hsfrey.flexlib.DynamicTextArea  */

                package com.hsfrey.flexlib

                {

                  public class DynamicTextArea extends TextArea

                  {

                       //...more code

                  }

                }

                 

                Make sure you nest DynamicTextArea in a series of subdirectories (com, hsfrey, flexlib).  The com directory needs to be in the same directory as application.MXML.

                • 5. Re: Error: "Could not resolve [public class] to a component implementation
                  hsfrey Level 1

                  Michael:

                   

                  When I remove DTA, I'm back to the original error "Could not resolve <DynamicTextArea> to a component installation"

                   

                  Is it impossible to declare and define a new class in the same file as the rest of the program?

                   

                  Harvey

                  • 6. Re: Error: "Could not resolve [public class] to a component implementation
                    hsfrey Level 1

                    myIP:

                     

                         No, the package is not in a separate file!

                    It is in the SAME file as the calls that instantiate the class.

                     

                         I would have thought that this would be the most straight-forward of declarations, but I don't see it adderssed in either the docs or my reference books.

                     

                    Harvey.

                    • 7. Re: Error: "Could not resolve [public class] to a component implementation
                      Michael Borbor Level 4

                      Oh I see you're trying to do that in the same file, no you can't. Create  a new file for your class, and then just import it into your application. I missed your first message where you said this is the file.

                      • 8. Re: Error: "Could not resolve [public class] to a component implementation
                        hsfrey Level 1

                        OK:

                         

                        The program now starts:

                         

                        <?xml version="1.0" encoding="utf-8" ?>
                        <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                        xmlns:DTA="DTA.as"
                        >
                             <mx:Script>
                            <![CDATA[
                              import mx.controls.Alert;
                              import DTA.*
                        <snip>

                         

                        The package is now in a file named DTA.as in the same folder as the program, and it starts:

                         

                        package DTA {
                          import flash.events.Event;
                          import mx.controls.TextArea;

                          public class DynamicTextArea extends TextArea{
                            public function DynamicTextArea(){

                         

                        <Snip>

                         

                        And I Still get the compiler error message: "could not resolve <DynamicTextArea> to a component implementation" for the calls to DynamicTextArea, whether or not I preface them with DTA.

                         

                        Again, I'm expecting it to work like the C Include statement for a *.h file.

                         

                        Harvey

                        • 9. Re: Error: "Could not resolve [public class] to a component implementation
                          Flex harUI Adobe Employee

                          And the tag now reads <DTA:DynamicTextArea /> ?

                           

                          Alex Harui

                          Flex SDK Developer

                          Adobe Systems Inc.

                          Blog: http://blogs.adobe.com/aharui

                          • 10. Re: Error: "Could not resolve [public class] to a component implementation
                            injpix Level 3

                            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                            xmlns:DTA="DTA.as"
                            >

                             

                            Thats incorrect.  To correctly do it the way you intend:

                             

                            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                            xmlns:DTA="*"
                            >


                              <!-- more code -->

                              <DTA:DynamicTextArea id="myCustomComponent" /> 


                            </mx:Application>

                             

                             

                            And then, your ActionScript class (DynamicTextArea.as) will be:

                             

                            package

                            {
                              import flash.events.Event;
                              import mx.controls.TextArea;

                              public class DynamicTextArea extends TextArea{
                                public function DynamicTextArea(){


                                 //...more code

                            • 11. Re: Error: "Could not resolve [public class] to a component implementationAlex:
                              hsfrey Level 1

                              Alex:

                               

                              Each of the invocations of the class is of the form:

                              <DTA:DynamicTextArea id="txt1" width="300" height="14"/>

                               

                              Here's the entire main file:

                               

                              <?xml version="1.0" encoding="utf-8" ?>
                              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                              xmlns:DTA="DTA.as"
                              >
                                   <mx:Script>
                                  <![CDATA[
                                    import mx.controls.Alert;
                                    import DTA.*
                                  
                                    private var str:String = "This text will be long enough to trigger " +
                                      "the TextArea to increase its height.";
                                    private var htmlStr:String = "This <b>text</b> will be <font color='#00FF00'>long enough</font> to trigger " +
                                      "the TextArea to increase its height.";
                                    private function setLargeText():void{
                                      txt1.text = str;
                                      txt2.text = str;
                                      txt3.text = str;
                                      txt4.text = str;
                                      txt5.htmlText = htmlStr;
                                      txt6.htmlText = htmlStr;
                                      txt7.htmlText = htmlStr;
                                      txt8.htmlText = htmlStr;
                                    }
                                  ]]>
                                </mx:Script>
                                <DTA:DynamicTextArea id="txt1" width="300" height="14"/>
                                <DTA:DynamicTextArea id="txt2" width="300" height="20"/>
                                <DTA:DynamicTextArea id="txt3" width="300" height="28"/>
                                <DTA:DynamicTextArea id="txt4" width="300" height="50"/>
                                <DTA:DynamicTextArea id="txt5" width="300" height="14"/>
                                <DTA:DynamicTextArea id="txt6" width="300" height="20"/>
                                <DTA:DynamicTextArea id="txt7" width="300" height="28"/>
                                <DTA:DynamicTextArea id="txt8" width="300" height="50"/>
                                <mx:Button label="Set Large Text" click="setLargeText();"/>
                              </mx:Application>

                               

                              Harvey

                              • 12. Re: Error: "Could not resolve [public class] to a component implementation
                                hsfrey Level 1

                                myIP:

                                 

                                     I've made the changes that I think you're recommending, and I now get the error message:

                                "Definition DTA could not be found"

                                 

                                The component file, DTA.as, in the same folder as the main program, now reads:

                                 

                                package {
                                  import flash.events.Event;
                                  import mx.controls.TextArea;

                                  public class DynamicTextArea extends TextArea{
                                    public function DynamicTextArea(){
                                <snip>

                                }}}

                                 

                                The main program now reads:

                                 

                                <?xml version="1.0" encoding="utf-8" ?>
                                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                xmlns:DTA="*"
                                >
                                     <mx:Script>    <![CDATA[
                                      import mx.controls.Alert;
                                      import DTA.*
                                    
                                      private var str:String = "This text will be long enough to trigger " +
                                        "the TextArea to increase its height.";
                                      private var htmlStr:String = "This <b>text</b> will be <font color='#00FF00'>long enough</font> to trigger " +
                                        "the TextArea to increase its height.";
                                      private function setLargeText():void{
                                        txt1.text = str;
                                <snip>

                                     }
                                    ]]>  </mx:Script>

                                <DTA:DynamicTextArea id="txt1" width="300" height="14"/>
                                <snip>

                                  <mx:Button label="Set Large Text" click="setLargeText();"/>
                                </mx:Application>

                                 

                                Isn't there some place where the exact syntax required is spelled out, say in BNF or something precise?

                                 

                                Harvey

                                • 13. Re: Error: "Could not resolve [public class] to a component implementation
                                  Michael Borbor Level 4

                                  Harvey in AS3 when you create classes you must name the file with the same name as your class.

                                   

                                  In your case your class is DynamicTextArea, so you must name that class file as DynamicTextArea.as

                                  • 14. Re: Error: "Could not resolve [public class] to a component implementation
                                    hsfrey Level 1

                                    Michael:

                                     

                                         I've renamed the component file  DynamicTextArea.as

                                     

                                    If the main file starts:

                                    <?xml version="1.0" encoding="utf-8" ?>
                                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                    xmlns:DTA="DynamicTextArea.*"
                                    >
                                         <mx:Script>
                                        <![CDATA[
                                          import mx.controls.Alert;
                                          import DynamicTextArea.as

                                     

                                    I get a compiler error message on the import statement: "Syntax error: expecting identifier before as"

                                     

                                    In looking up the syntax, I find about importing in Flex Builder, importing mx classes, importing XML, importing CSS, Embedding assets, etc,

                                    but I don't see anything about the syntax of importing my own class.

                                     

                                    I assume the "identifier" the compiler expects is like the 'mx' before a flex asset, but what is it for an asset I've defined?

                                     

                                    Harvey

                                    • 15. Re: Error: "Could not resolve [public class] to a component implementation
                                      Michael Borbor Level 4

                                      Harvey

                                       

                                      import DynamicTextArea.as
                                      

                                      In this case you don't add the .as, remove it. The alert begins with an mx because that's the main folder where all Flex only classes go, you shouldn't have to worry to understand that now.

                                       

                                      This

                                       

                                      xmlns:DTA="DynamicTextArea.*"
                                      

                                      In this case DynamicTextArea will be a folder, and inside that folder will be your class, if you have your custom class in the same folder that you have your app aKa the default package you only need to define it like this

                                       

                                      xmlns:DTA="*"
                                      • 16. Re: Error: "Could not resolve [public class] to a component implementation
                                        hsfrey Level 1

                                        Michael:

                                         

                                             VOILA! It Compiles!

                                         

                                             Thanks to all you guys for hanging in there with me!

                                         

                                             Now, is there someplace where syntax like that is spelled out? So far I've got 4 thick books on Flex, plus the entire internet

                                        and Adobe's langref and tutorials, and I was unable to find it.

                                         

                                             Thanks, again!

                                         

                                        Harvey

                                        • 17. Re: Error: "Could not resolve [public class] to a component implementation
                                          Michael Borbor Level 4

                                          Probably because it's not a Flex only stuff, but more of an ActionScript thing. You said you've got four thick books, so you enjoy reading which is great. If you really want to master Flex, I recommend you to read Essential ActionScript 3.0 by Colin Moock, it's a great resource to understand pretty much everything else in Flex/Flash/Flash Player.

                                          • 18. Re: Error: "Could not resolve [public class] to a component implementation
                                            hsfrey Level 1

                                            Michael:

                                             

                                                 LOL! OK, I'll make it FIVE thick books!

                                             

                                                 Reminds me of the old New Yorker cartoon, where a doctor is looking at his bookshelf and says to the patient

                                            "Somewhere on those shelves is the answer".  <G>

                                             

                                            Harvey

                                            • 19. Re: Error: "Could not resolve [public class] to a component implementation
                                              Michael Borbor Level 4

                                              Ha ha . Actually you don't need to buy this book, but if you do you'll learn a lot.

                                               

                                              In the Flex Builder documentation there's a full chapter named Programming ActionScript 3.0, if you have Flex Builder installed you can read it in the Documentation or you can download it as PDF.

                                              • 20. Re: Error: "Could not resolve [public class] to a component implementation
                                                hsfrey Level 1

                                                Thanks to the lightning speed of the internet, I've already placed the order.

                                                 

                                                It's just as well - I can't underline the online copies.

                                                 

                                                Harvey

                                                • 22. Re: Error: "Could not resolve [public class] to a component implementation
                                                  GordonSmith Level 4

                                                  Harvey, I've emailed the manager of the Flex documentation team to make him aware of your difficulties in getting your first custom component to compile successfully.

                                                   

                                                  Gordon Smith

                                                  Adobe Flex SDK Team

                                                  • 23. Re: Error: "Could not resolve [public class] to a component implementation
                                                    hsfrey Level 1

                                                    Thanks Gordon!

                                                     

                                                    Maybe I'm just a bit dense. But my ideal for documentation is Kernihan & Ritchie. I read it about 30 years ago and was writing C within days.(Maybe part of my problem is breaking out of that mode of thinking.)

                                                     

                                                    Admittedly Flex and ActionScript are much larger languages, but the trick of K&R was that they concentrated on the core syntax, and relegated the rest to specialized libraries.

                                                     

                                                    The problem with teaching by example is that it's not always easy to generalize, or even to know what is language, what is convention, and what is particular to the example.

                                                     

                                                    What Michael told me was a simple rule that made everything clear. I wasn't able to extract that rule myself from looking at many disparate examples.

                                                     

                                                    I think your team could do worse than to have another look at K&R!

                                                     

                                                    Harvey

                                                    • 24. Re: Error: "Could not resolve [public class] to a component implementation
                                                      GordonSmith Level 4

                                                      It's interesting that you mentioned K&R. Recently two extremely experienced Adobe engineers who were unfamiliar with Flex started looking at it and on the second day asked "Where's the equivalent of K&R for Flex?". So you're not the only one who feels that we may not be presenting the basics for Day 1 (or maybe Week 1) in the right way.

                                                       

                                                       

                                                      This was a long thread, so can you point out what was the critical "Aha!" pieces of information that you were missing? The things I noticed were:

                                                       

                                                       

                                                      • Trying to define a class inside a <Script> block.
                                                      • Putting statements to execute, rather than const/var/function declarations, inside a <Script> block.
                                                      • Omitting the namespaces on a component tag.
                                                      • Confusing a package name with an XML namespace prefix.
                                                      • Using an AS file name as an XML namespace value.
                                                      • Trying to import an AS file name.

                                                       

                                                       

                                                      Gordon Smith

                                                      Adobe Flex SDK Team

                                                      • 25. Re: Error: "Could not resolve [public class] to a component implementation
                                                        hsfrey Level 1

                                                        Gordon:
                                                            As you've noted, there were multiple  misunderstandings.
                                                            Some are due to references in the language which are  different from uses in pre-existing languages.
                                                            Take "name spaces". They look like URLs but they're  not. One of the first errors I made when starting Flex was to try to browse to  http://www.adobe.com/2006/mxml. I  figured that it would have some description of the language. But it didn't. In  spite of LOOKING like a URL, it doesn't point to anything; it's really just an  arbitrary magic incantation, like "Open Sesame".
                                                            But, then when I wanted to use my OWN namespace, I  find that it's NOT arbitrary, and does have to point to something, but it's  still not a URL. The "AHA" moment was when Michael told me that "*" means "look  in this directory for a file with the name later named in an import statement,  but not named here". And if the file was in subfolder  "X" I'd have to use "X.*", while if it were a URL I'd use slash instead of  dot, but never an asterisk.
                                                            When the language syntax is so contrary to the  expectations of people coming from a declarative language or web programming  background, I think it is important to explicitly address the differences and  disabuse them of their preconceptions. I think the same should apply to the ways  in which ActionScript differs from ECMAScript.
                                                            Another problem adding to my confusion is the habit  of naming variables with the names of keywords but with capitalization changes.  Not only does that set readers up for subtle "gotchas", but makes it unclear  which names are truly arbitrary, and which are required by the  compiler.
                                                        It might be a good idea to have a convention of an  identifiable format for user variables. Many authors use names like  myButton for that purpose.
                                                            It would also be helpful if printed text could  simulate the syntax coloring of the better editors, or at least have more  in-source comments saying exactly what each line does. (Or both)
                                                            Another aid to understanding would be to provide a  reference to the alternative (MXML or AS) way of doing anything, whenever you  demonstrate one of the ways.
                                                            I find that the emphasis on using FlexBuilder  distracts from a sense of what is really going on behind the scenes. E,g.: If  FlexBuilder automatically sets up the folder structure, I don't learn to do it  myself. I like to work at the code level, so when something goes wrong I don't  have to worry about what level it went wrong at.
                                                            Also, not everyone is willing to drop $600 or $250  BEFORE they've learned whether they even like Flex. Your tutorials are, by  definition, addressed to newcomers who may well not yet have committed to the  expense of FlexBuilder. So more emphasis on using mxmlc would be nice. It would  also be helpful to discuss how to use local servers, like Tomcat, during the  development stage.
                                                            Thanks for asking my opinion. I'm afraid that my 40  years of programming experience may make it harder for me to adapt to this new  style of programming than it would be for a kid with a tabula rasa. But, it  looks like it'll be fun once I get over the hump!
                                                        Harvey