2 Replies Latest reply on Jan 25, 2007 8:44 AM by ur_dtrain

    accessing public variables

      I have the code below. What I am trying to do is to print out the value of a public variable. I am trying to change that public variable in the function that handles the result of the remote object call. The problem is the value only seems to change in the function and no where else. Any ideas?


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="load_list()">

      <mx:script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;

      [Bindable]
      public var material1_ID: int;

      public function load_list():void{
      material1_ID = 0;
      }

      public function addRec():void{
      Alert.show('value before' + material1_ID.toString());
      insertService.addMaterial('123'); // THis calls my webservice and returns a query
      Alert.show('value after' + material1_ID.toString());
      }

      public function addMaterial(event:ResultEvent):void{
      material1_ID = 9;
      }
      ]]>
      </mx:Script>

      <mx:RemoteObject
      id ="insertService"
      destination="ColdFusion"
      source ="insert"
      >
      <mx:method name="addMaterial" result="addMaterial(event)" >
      </mx:RemoteObject>

      </mx:Application>
        • 1. Re: accessing public variables
          peterent Level 2
          This function in your code:
          public function addRec():void{
          Alert.show('value before' + material1_ID.toString());
          insertService.addMaterial('123'); // THis calls my webservice and returns a query
          Alert.show('value after' + material1_ID.toString());
          }

          Looks to me like you are making the remote call and then expecting the next line to access the result. Flex doesn't work that way. Remote calls (including HTTPService and WebService) are asynchronous. When you make the addMaterial call, the request goes out and the response comes back "later". So right after that request the value won't be changed.

          If you print the value in the result handler, you'll see that it will be changed.
          • 2. Re: accessing public variables
            ur_dtrain Level 1
            In addition, inside any class use:
            import mx.core.Application;

            Then the object 'Application.application' will give you access to any global variables from anywhere within the application.
            1 person found this helpful