2 Replies Latest reply on May 27, 2008 12:10 PM by josh_aries

    WebService and ActionScript class

    josh_aries
      Hi,
      I am trying to create an actionscript class to use it in my mxml component.

      I have the floowing code which works perfectly.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application creationComplete="HTTPdecision.send()" xmlns:mx=" http://www.adobe.com/2006/mxml" width="870">
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import com.sourcepulse.com.dtRulesClass;

      private var endURI:XML;
      private var URI:XMLList;

      private function setURI(event:ResultEvent):void
      {
      endURI = event.result as XML;
      URI = new XMLList(endURI.endpoint.webservice.location);
      Test.endpointURI= URI.toString();
      }


      ]]>
      </mx:Script>
      <mx:HTTPService id="HTTPdecision" url="../XML/endpointURI.xml" resultFormat="e4x" result="setURI(event)" />
      <mx:WebService service="amazon" port="amazonSOAP" id="Test"
      wsdl=" http://localhost:9081/ezbuyer/amazon/services/amazonSOAP/wsdl/amazon.wsdl" >
      <mx:operation name="getISBNDetails">
      <mx:request xmlns="">
      <isbnSearchRequest>
      <bookName>{txtBookName.text}</bookName>
      <category>{txtCategory.text}</category>
      </isbnSearchRequest>
      </mx:request>
      </mx:operation>
      </mx:WebService>
      <mx:Panel x="100" y="100" width="600" height="500" layout="absolute"
      title="Amazon WebService">
      <mx:VBox height="400">
      <mx:VBox>
      <mx:Form width="400" height="145" autoLayout="true">
      <mx:FormHeading label="Specify the following:"/>
      <mx:FormItem width="307" label="BookName :">
      <mx:TextInput id="txtBookName"/>
      </mx:FormItem>
      <mx:FormItem width="308" label="Category :">
      <mx:TextInput id="txtCategory" />
      </mx:FormItem>
      <mx:FormItem width="312">
      <mx:Button label="Test" click="Test.getISBNDetails.send()"/>
      </mx:FormItem>
      </mx:Form>
      </mx:VBox>
      <mx:VBox>
      <mx:Form width="400" height="122" autoLayout="true">
      <mx:FormHeading label="Book Details:"/>
      <mx:FormItem width="307" label="ISBN :">
      <mx:Text text="{Test.getISBNDetails.lastResult.isbn}" />
      </mx:FormItem>
      <mx:FormItem width="308" label="Author :">
      <mx:Text text="{Test.getISBNDetails.lastResult.author}" />
      </mx:FormItem>
      </mx:Form>
      </mx:VBox>
      </mx:VBox>
      </mx:Panel>
      </mx:Application>


      Now instead of binding the input from the textboxes directly as in the above code

      <mx:request xmlns="">
      <isbnSearchRequest>
      <bookName>{txtBookName.text}</bookName>
      <category>{txtCategory.text}</category>
      </isbnSearchRequest>
      </mx:request>

      I created an actionscript class

      package com.xxxx.com
      {
      public class simpleTest
      {
      //Instance Variables
      private var bookName:String;
      private var category:String;

      public function simpleTest()
      {
      }

      function getBookName():String {
      return bookName;
      }

      function setBookName(bookName:String):Void {
      this.bookName = bookName;
      }

      function getCategory():String {
      return category;
      }

      function setCategory(category:String):Void {
      this.category = category;
      }


      }
      }

      How can I use this ActionScript class to use in <bookName>{txtBookName.text}</bookName>.

      Thanks in advance.
        • 1. Re: WebService and ActionScript class
          ctzn99 Level 1
          I think you're close to achieving what you want... first I would change your getter and setter methods just a bit to make them properties. Second add the [Bindable] meta tag in front of one of each of the group of properties (i.e. you don't need it in front of both the get and set method, just one of them).

          i.e.

          [Bindable]
          public function get category():String {
          return category;
          }

          public function set category(value:String):void{
          category = value;
          }

          then in your mxml you can "bind" to each property you've defined in the class. so if you create a new instance of your simpleTest class called "test" you could do the following:

          <mx:Label text="{test.category}" />
          • 2. Re: WebService and ActionScript class
            josh_aries Level 1
            Thanks for the reply. I made changes to the class file. I am trying to create the object of the class as

            import com.xxxx.com.Test;

            var testData : com.xxxx.com.Test = new Test();
            testData.setBookName("Java 5");

            I get the following error.

            1120: Access of undefined property testData