10 Replies Latest reply on May 23, 2006 12:03 PM by Remco805

    Cannot extend mx.core.Application

    firdosh Level 1
      I am trying to create a AS3 only project with no mxml but I would like to use the mx.controls
      I created a simple class

      package {
      import mx.core.*;
      import mx.containers.*;
      import mx.controls.*;
      import flash.display.*;

      public class Test extends Application {
      public function Test(){

      }
      }
      }

      The code compiles fine but generates errors during runtime

      TypeError: Error #1006: Call attempted on an object that is not a function.
      at mx.core::Container/mx.core:Container::createBorder()
      at mx.core::Container/styleChanged()
      at mx.core::Application/styleChanged()
      at mx.managers::SystemManager/ http://www.adobe.com/2006/flex/mx/internal::addingChild()
      at mx.managers::SystemManager/::initializeTopLevelWindow()
      at mx.managers::SystemManager/::frameEndHandler()



      thanks
      cheers :)
      firdosh
        • 1. Re: Cannot extend mx.core.Application
          utraum
          this works for me:


          in constructor:
          {
          super();
          addEventListener(FlexEvent.APPLICATION_COMPLETE,appComplete);
          }

          everything else in appComplete
          • 2. Re: Cannot extend mx.core.Application
            firdosh Level 1
            hey utraum ,
            I modified my code

            package {
            import mx.core.*;
            import mx.containers.*;
            import mx.controls.*;
            import mx.events.*;
            import flash.display.*;

            public class Test extends Application {
            public function Test(){
            super();
            addEventListener(FlexEvent.APPLICATION_COMPLETE,appComplete);
            }

            private function appComplete():void{

            }
            }
            }

            but I still get the runtime errors.

            Are there any compiler options ur specifying when compling the files.

            I simply use mxmlc Test.as

            thanks
            cheers :)
            firdosh
            • 3. Re: Cannot extend mx.core.Application
              GordonSmith Level 4
              We've made subclassing components in AS straightforward, but subclassing Application isn't trivial. There is some support code that an Application needs thatI the MXML compiler sets up. think you're running into the problem that you don't have a global CSS selector. (The MXML compiler parses default.css and creates ActionScript that sets up the CSSStyleDeclarations that the application needs.) We can probably make this easier in the next release, but it's unlikely to get better for Flex 2. Is there some particular reason why your app can't be an MXML file, or it is just a preference?

              Another possibiliy is to turn on the keep-generated-actionscript option, compile an empty <mx:Application/> app, look at the subclass of Application that the MXML compiler produces, and copy any relevant -looking autogenerated code you find there.
              • 4. Re: Cannot extend mx.core.Application
                utraum Level 1
                I am using an simple mxml file, which only includes my new Application-class. This may be a reason for the difference.
                • 5. Re: Cannot extend mx.core.Application
                  firdosh Level 1
                  Hey guys thanks for all the responses.
                  I took Gordons advice and used the keep-generated-actionscript ( would be cool to add it to the compiler list help ) and went through all the as files it generates.
                  there is a class called [classname]_mx_managers_SystemManager which is created but when I try to add it

                  [Frame(factoryClass="Test_mx_managers_SystemManager")]

                  in Test.as class I get a compiler error

                  Error: Unable to resolve a class for factoryClass: Test_mx_managers_SystemManager.

                  it works fine for the other classes though.

                  thanks
                  cheers :)
                  firdosh
                  • 6. Re: Cannot extend mx.core.Application
                    GordonSmith Level 4
                    The MXML compiler autogenerates a fair amount of code when you use <mx:Application>, but I don't think we hide any of it. One of the files in the generated folder should have the autogenerated class Test_mx_managers_SystemManager.
                    • 7. Re: Cannot extend mx.core.Application
                      firdosh Level 1
                      Hey Gordon ,
                      the generated folder does have that file but it still gives me that error which is why I was confused. There is another file _Text_FlexInit".as for which when I add the code.

                      [Frame (extraClass = "_Text_FlexInit")]

                      Works fine. but gives an error for the Test_mx_managers_SystemManager class
                      even though its there in the generated folder.

                      thanks
                      cheers
                      firdosh

                      • 8. Re: Cannot extend mx.core.Application
                        GordonSmith Level 4
                        Like I said, we haven't done any work to make this easy. What's wrong with using MXML to create your Application subclass?
                        • 9. Re: Cannot extend mx.core.Application
                          firdosh Level 1
                          Well a lot of people have been trying to create a AS3 only project but use the flex components [ cause they are super cool :) ].
                          The whole point of not using mxml was to create a pure AS3 project. Also while looking at the generated classes I came accross
                          EffectManager.mx_internal::registerEffectTrigger (); // what are the double colons signify ??
                          and
                          [Mixin] //

                          thanks
                          cheers :)
                          firdosh
                          • 10. Re: Cannot extend mx.core.Application
                            Remco805
                            There's nothing wrong with MXML application, but.. as a java programmer i 'd like to understand all of the code (and be in controll). An as3-only-project with MX components seems more "pure". MXML = view, the flex builder is amazing!! but the other stuff should be actionscript only.