7 Replies Latest reply on Jul 6, 2007 4:04 AM by MannenMytenLegenden

    How to create a new class

    MannenMytenLegenden
      Hi,

      I'm trying to create a new class called Questions, which has two properties (type and condition).
      The action script is saved in the folder myComponents under the project.

      When I compile the Main app, I get the following error message:
      "1172 Definition myComponents:Question could not be found."
      Why?

      How do you call a constructor for a new class, that is not an extension of an existing class?

      Regards
      /Acke

      //-----------Class----------//
      package myComponents
      {
      // Import all classes in the mx.events package
      import mx.events.*;

      public class Question {

      // Public constructor.
      public var Question(){
      // Call the constructor in the superclass.
      //super();
      }
      // Define properties and methods.
      // Define public vars.
      public var type:string;
      public var condition:string;
      }
      }

      //------Main----------//
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      xmlns:MyComp="myComponents.*">

      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.events.CloseEvent;
      import myComponents.Question;
      etc, etc....

        • 1. Re: How to create a new class
          Robert Hirst Level 1
          I think there is an error in your declaration of the construction. It's defined as a var, and it should be a function.

          public var Question(){

          should be

          public function Question(){
          • 2. Re: How to create a new class
            MannenMytenLegenden Level 1
            Thanks.
            But that gave the same error anyway.

            I will post an answer when/if I find one.

            Regards
            Acke
            • 3. Re: How to create a new class
              shawnoshawnuth
              quote:

              Originally posted by: MannenMytenLegenden
              Hi,

              I'm trying to create a new class called Questions, which has two properties (type and condition).
              The action script is saved in the folder myComponents under the project.

              When I compile the Main app, I get the following error message:
              "1172 Definition myComponents:Question could not be found."
              Why?

              How do you call a constructor for a new class, that is not an extension of an existing class?

              Regards
              /Acke

              //-----------Class----------//
              package myComponents
              {
              // Import all classes in the mx.events package
              import mx.events.*;

              public class Question {

              // Public constructor.
              public var Question(){
              // Call the constructor in the superclass.
              //super();
              }
              // Define properties and methods.
              // Define public vars.
              public var type:string;
              public var condition:string;
              }
              }

              //------Main----------//
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
              xmlns:MyComp="myComponents.*">

              <mx:Script>
              <![CDATA[
              import mx.controls.Alert;
              import mx.events.CloseEvent;
              import myComponents.Question;
              etc, etc....




              Here is a test class I created a while back, although this one does extend Object it might help you out a bit with your constructor issue:

              package com.evilest

              {
              import mx.controls.Alert;

              public class Testing_class extends Object
              {
              private var message:String = new String();

              public function Testing_class(input:String) {
              this.message = input;
              }

              public function showAlert():void {
              Alert.show(this.message, "sup");
              }

              }
              }
              • 4. How to create a new class
                levancho Level 3
                if you are not doing anything in Question constructor you dont even need to define it , compiler will do it for you.
                so remove
                public var Question(){
                // Call the constructor in the superclass.
                //super();
                }
                it will work, but if you persist to have it there, change it to
                public function Question(){
                // Call the constructor in the superclass.
                //super();
                }

                also this code assumes that you main.mxml file is one directory up of you "myComponents" folder
                • 5. How to create a new class
                  MannenMytenLegenden Level 1
                  Stupid me!!

                  I have two projects, Quest and AutoQuest, and I saved it under the wrong one!.

                  So, now it imports as it should.

                  Thanks everyone for your efforts.

                  Regards
                  Acke
                  • 6. Re: How to create a new class
                    Robert Hirst Level 1
                    Is the class in a file called Question.as?
                    • 7. Re: How to create a new class
                      MannenMytenLegenden Level 1
                      Se my previous message.

                      Acke