7 Replies Latest reply on Feb 12, 2008 10:33 AM by uniqode

    Having a problem with Date class

    uniqode
      I am trying to display the current date in a component. I create a new date object in AS with

      var n:Date = new Date();

      However, I keep getting the error:
      "Type was not found or was not a compile-time constant: Date"

      Isn't date a top level class? do I still need to import something? When I do the same in the main application file it works just fine but it does not in the component...

      Thanks for any input in advance...
        • 1. Re: Having a problem with Date class
          atta707 Level 2
          Date is indeed top level! Some code of the component may be helpful in seeing the problem.
          • 2. Re: Having a problem with Date class
            Gregory Lafrance Level 6
            I tried hard but I couldn't get that error in an MXML component, in an ActionScript class, or in the main app. Guess we do need to see some of your code.
            • 3. Re: Having a problem with Date class
              uniqode Level 1
              Thank you both for the input, here is the component code


              <?xml version="1.0" encoding="utf-8"?>
              <cfComponents:SizeableTitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*"
              xmlns:cfComponents="com.adobe.ColdFusion.components.*"
              creationComplete="initComponent()"
              title="Show Related Time"
              showCloseButton="true" close="WindowManager.remove(this);" width="600" height="800" >

              <mx:Script>
              <![CDATA[
              import mx.charts.chartClasses.DataDescription;
              import com.adobe.windowedApplication.managers.WindowManager;
              import mx.core.UIComponent;
              import mx.collections.ArrayCollection;
              import mx.utils.ObjectUtil;
              import mx.controls.Alert;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;


              private var getDate:Date = new Date();
              private var _key:Object;

              [Bindable]
              public function get key():Object
              {
              return this._key;
              }
              public function set key(key:Object):void
              {
              this._key = key;
              }
              private function initComponent():void
              {
              refreshList(null);
              }

              public function refreshList(event:Event):void
              {
              this.dataManagerPO.getById(this.key);
              }
              private function getMasterQuery_result(event:ResultEvent):void
              {
              //Use the ClientID to get Client details
              this.dataManagerClient.get(event.result.ClientID);
              //Assign the PO details to related fields
              OrderNumber.text= event.result.PONo;
              WorkDoneFor.text = event.result.POProject;
              Issuer.text = event.result.Issuer;
              Date.text = ((getDate.getMonth() + 1) + "/" + getDate.getDate() + "/" + getDate.getFullYear());

              }
              private function getClientQuery_result(event:ResultEvent):void
              {
              //Assign the client and the details to related fields
              clientDetails.text = event.result.Client + "\n" + event.result.Address + "\n" +
              event.result.City + ", " + event.result.State + " " + event.result.Zip + " " + event.result.Country;
              InvoiceData.client.id = event.result.ClientID;
              Alert.show(InvoiceData.number);
              }
              private function server_fault(event:FaultEvent):void
              {
              // dump error message
              Alert.show( ObjectUtil.toString(event.fault) );
              }
              ]]>
              </mx:Script>
              <mx:RemoteObject
              id="dataManagerPO"
              showBusyCursor="true"
              destination="ColdFusion" source="flexacct.components.cfgenerated.POs.purchaseordersGateway">
              <mx:method name="getById" result="getMasterQuery_result(event)" fault="server_fault(event)" />
              </mx:RemoteObject>
              .
              .
              .
              .
              .
              </cfComponents:SizeableTitleWindow>
              • 4. Re: Having a problem with Date class
                ntsiii Level 3
                That line, var n:Date = new Date(); is not in the posted code.

                Which line is causing the error?

                If it is the line near the top: "private var getDate:Date = new Date();", then do not attempt to initialize the variable in a top level script block. Instead, do it in an init() function called by the creationComplete event. Only very simple assignments can be done outsode of a function.

                If you want to know why, I can find an explanation.

                Tracy
                • 5. Re: Having a problem with Date class
                  uniqode Level 1
                  Thanks Tracy. Yes, that is the line that causes the problem.

                  Unfortunately it does not change anything to move it under a init function. It does not like the "date" type overall in the component.

                  For instance, I replace that line with

                  public function newdate(N:Date):void
                  {

                  }

                  and I keep getting the same error message. Any ideas?
                  • 6. Re: Having a problem with Date class
                    Gregory Lafrance Level 6
                    This code works. I wonder if your namespaces are messed up.

                    ---------------------------- Test.mxml -------------------------------
                    <?xml version="1.0"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*">
                    <TestComp/>
                    </mx:Application>
                    ---------------------------------- TextComp.mxml ----------------------
                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml"
                    creationComplete="initComponent()">

                    <mx:Script>
                    <![CDATA[
                    import mx.core.UIComponent;
                    import mx.collections.ArrayCollection;
                    import mx.utils.ObjectUtil;

                    private var myDate:Date = new Date();

                    private function initComponent():void
                    {
                    trace(myDate);
                    }
                    ]]>
                    </mx:Script>
                    </mx:Panel>
                    • 7. Re: Having a problem with Date class
                      uniqode Level 1
                      Greg, thanks for trying, I really appreciate it.

                      It does work with that test code you created. But it still does not with my component "cfComponents:SizeableTitleWindow". I think it has something to do with the component type (I have no idea why) but I spent enough time on this that I am quitting as I am super frustrated. I will just create the date in the main application file and use it as a variable in the component.

                      Cheers
                      Emre