3 Replies Latest reply on Jul 12, 2007 1:45 AM by Mitek17

    Error when defining a variable from a class

    MannenMytenLegenden
      Hi,

      I'm getting this error message when trying to define a variable from a class:
      '1086: Syntax error: expecting semicolon before left paren.'

      I can't see where the error is.
      The scripts Question.as and Codeframe.as is located int the folder Mycomponents under the project.

      Regards
      /Acke

      **** Main app *****
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.events.CloseEvent;
      import myComponents.*;

      var Question():myComponents.Question=new Question(); // !! This line causes the error !!

      other code goes here....
      ]]>
      </mx:Script>

      **** The class definition ******
      package myComponents
      {
      //import other classes needed
      import Mycomponents.Codeframe

      public class Question {

      // Define properties and methods.
      // Define public vars.
      public var Qtype:string;
      public var Condition:string;
      public var Qnumber:string;
      public var Qheading:string;
      public var Pretext:string;
      public var Qtext:string;
      public var Posttext:string;
      public var Codeframe():string;
      public var Reserved:string;
      public var EditableFrom:string;
      public var EditableTo:string;
      public var Decimal:string;
      public var SetQfactor:string;
      public var Logic_if():string;
      public var Logic_then():string;

      // Public constructor.
      //public function Question(){
      // do stuff to set initial values for properties
      }

      public function Question(Type:string,
      Condition:string,
      Qnumber:string,
      Qheading:string,
      Pretext:string,
      Qtext:string,
      Posttext:string,
      Codeframe():string,
      Reserved:string,
      EditableFrom:string,
      EditableTo:string,
      Decimal:string,
      SetQfactor:string,
      Logic_if():string,
      Logic_then():string,
      ):Void
      {
      this.Type=Type;
      this.Condition=Condition;
      this.Qnumber=Qnumber;
      this.Qheading=Qheading;
      this.Pretext=Pretext;
      this.Qtext=Qtext;
      this.Posttext=Posttext;
      this.Codeframe()=Codeframe();
      this.Reserved=Reserved;
      this.EditableFrom=EditableFrom;
      this.EditableTo=EditableTo;
      this.Decimal=Decimal;
      this.SetQfactor=SetQfactor;
      this.Logic_if()=Logic_if();
      this.Logic_then()=Logic_then();
      } */
      }
      }
        • 1. Re: Error when defining a variable from a class
          drofnasnhoj
          i think what you are trying to do is this:

          var theQuestion:Question = new Question();

          You don't want to name the variable the same thing as the class, and since you are already importing "myComponents.*" you don't need to pre-pend "myComponents." when creating the variable.

          Hope that works for you.
          • 2. Re: Error when defining a variable from a class
            MannenMytenLegenden Level 1
            Thx,

            I have tried some variants of what you suggested.

            var Question():Question=new Question();
            var Question():Array=new Question(); // I'm trying to create an array here anyway...could this be the problem??
            var Qs():Question=new Question();
            .var Qs()=new Question();
            ..
            None seems to work!

            If I start writing... Question(). I can see all properties of the class.
            The class is alright...but the declaration of the variable is not in some way...

            Regards
            /Acke
            • 3. Re: Error when defining a variable from a class
              Mitek17 Level 1
              1.
              It should be
              var theQuestion:Question = new Question(sType,sCondition:string,sQnumber,sQheading,sPretext,sQtext,sPosttext, sCodeframe,sReserved,sEditableFrom,sEditableTo,sDecimal,sSetQfactor,sLogic_if,sLogic_then )

              As you don't have default values in the constructor - you should specify the parameters.

              2. why do use type "string" ? It should be "String" if you refer to a standard type

              3. What are you trying to say by this:
              public var Codeframe():string;
              public var Logic_if():string;
              public var Logic_then():string;

              There should not be any parenthesis in the variable declaration.

              4.
              this is wrong
              var Question():Question=new Question();

              this even wronger
              var Question():Array=new Question(); // I'm trying to create an array here anyway...could this be the problem??

              no parenthesis!
              var Qs():Question=new Question();

              hmmmm....
              .var Qs()=new Question();

              I think you should start reading from the following link to get more understanding of the variables, types & declarations:

              http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDo cs_Parts&file=00001863.html

              Cheers,
              Dmitri.