9 Replies Latest reply on Oct 29, 2008 2:29 PM by Newsgroup_User

    Post Variables Using Actionscript

    alice_data Level 1
      Hi,

      I have seen on the docs that we could write HTTPService in Actionscript method. I have completed the entire section based on the description of the method defined on the doc, but I am having some issues defining the variables to pass to the actual service (mx:request as in MXML).

      I need to know the actual variable that gets passed to the service, because I would like to reuse the information returned from the service for further edits. Since this information is not stored in the XML, I wonder if anyone can tell me what is wrong with the syntax below? Currently, all I get is this error:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.

      Anything is appreciated.
        • 1. Re: Post Variables Using Actionscript
          Level 7

          "alice_data" <webforumsuser@macromedia.com> wrote in message
          news:ge7smi$cea$1@forums.macromedia.com...
          > Hi,
          >
          > I have seen on the docs that we could write HTTPService in Actionscript
          > method. I have completed the entire section based on the description of
          > the
          > method defined on the doc, but I am having some issues defining the
          > variables
          > to pass to the actual service (mx:request as in MXML).
          >
          > I need to know the actual variable that gets passed to the service,
          > because
          > I would like to reuse the information returned from the service for
          > further
          > edits. Since this information is not stored in the XML, I wonder if anyone
          > can
          > tell me what is wrong with the syntax below? Currently, all I get is this
          > error:
          >
          > TypeError: Error #1009: Cannot access a property or method of a null
          > object
          > reference.

          at which line?


          • 2. Post Variables Using Actionscript
            alice_data Level 1
            Hi, Amy:

            Looks like that the output does not like my calling variables like request.data.population = "population"; , even though all I am doing here is similar to the function in mx:request by defining the variables.

            Here is the error I get:

            TypeError: Error #1009: Cannot access a property or method of a null object reference.
            at test/useHttpService()
            at test/__mySubmitButton_click()

            Have I declared the functions where I execute the HTTPService wrong?
            Thanks in advance.

            Alice

            Alice
            • 3. Re: Post Variables Using Actionscript
              Level 7

              "alice_data" <webforumsuser@macromedia.com> wrote in message
              news:ge8gan$83p$1@forums.macromedia.com...
              > Hi, Amy:
              >
              > Looks like that the output does not like my calling variables like
              > request.data.population = "population"; , even though all I am doing here
              > is
              > similar to the function in mx:request by defining the variables.
              >
              > Since the root node of the XML output is year, I tried doing
              > request.year.population="population", and it still gave me the same error.
              > Does
              > this provide you enough information about my errors?

              I think the problem is that you typed your variable as an HTTPService, but
              then you try to fill it with a URLLoader. I'm amazed you didn't get a
              compile time warning of an implicit coercion of type URLLoader to unrelated
              type HTTPService.

              You can't add extra properties to the built in objects (except Object of
              course), so there is no way that you could attach a year property to either
              a HTTPService or a URLRequest. That means that the above would never work,
              and, again, I'm amazed you didn't get a compile-time error about an attempt
              to access possibly undefined property year.

              I'm thinking you _are_ getting compile-time errors, but you're ignoring them
              and running the file anyway. The best advice I can give you is to pay
              attention to warnings and errors, and don't try to go ahead when you're
              getting them.

              HTH;

              Amy


              • 4. Post Variables Using Actionscript
                alice_data Level 1
                Hi, Amy:

                Sorry, but I think I am getting a little confused at this point. I have changed my code to the following, but now I get errors that say 1119: Access of possibly undefined property data through a reference with static type on the line where I declare my variables to send to the HTTPService.

                Part of the problems with the error I have been getting is that I am not sure what to define my parameters as, but again I tried to take the parameter definition from the following line, it tells me I need one argument: <mx:Button label="Submit" id="mySubmitButton" click="useHttpService()"/>. What should I put in the parenthesis?

                The doc I referred to is at http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=dataservices_099_15.html, but I think my main problem here is that I am not sure how to define the variables and pass it to the actual service and have the variables be handled internally through Actionscript. Or, is what I trying to accomplish here not possible at all?


                Thanks for your help.

                Alice
                • 5. Re: Post Variables Using Actionscript
                  Level 7

                  "alice_data" <webforumsuser@macromedia.com> wrote in message
                  news:ge9nf1$1ai$1@forums.macromedia.com...
                  > Hi, Amy:
                  >
                  > Sorry, but I think I am getting a little confused at this point. I have
                  > removed
                  > var loader:URLLoader = new URLLoader();
                  > loader.addEventListener(Event.COMPLETE, function(event:Event):void {
                  > trace("finished sending and loading: "+ loader.data);
                  > });
                  > loader.load(request);
                  > and ran the code again and received the same error as before.
                  >
                  > Part of the problems with the error I have been getting is that I have
                  > not
                  > defined my parameters correctly, but again I tried to take the parameter
                  > definition from the following line, it tells me I need one argument:
                  > <mx:Button
                  > label="Submit" id="mySubmitButton" click="useHttpService()"/>. What should
                  > I
                  > put in the parenthesis?
                  >
                  > The doc I referred to is at
                  > http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?co
                  > ntext=LiveDocs_Book_Parts&file=dataservices_099_15.html, but I think my
                  > main
                  > problem here is that I am not sure how to define the variables and pass it
                  > to
                  > the actual service and have the variables be handled internally through
                  > Actionscript. Or, is what I trying to accomplish here not possible at all?

                  Try changing this:
                  private var request:HTTPService;
                  to
                  private var request: URLRequest;

                  I still think you're getting a lot of warnings you're ignoring (check the
                  problems tab). You should have gotten a duplicate variable definition for
                  what you had.

                  What you're trying to accomplish is possible, but you DO need to pay
                  attention to the warnings and errors Flex is trying to tell you about. They
                  are your friend.


                  • 6. Post Variables Using Actionscript
                    alice_data Level 1
                    Hi, Amy:

                    Thanks for your help. I have modified my code based on some event Listeners and urlLoaders, and now everything is working!
                    • 7. Re: Post Variables Using Actionscript
                      Level 7

                      "alice_data" <webforumsuser@macromedia.com> wrote in message
                      news:ge9tcl$9g7$1@forums.macromedia.com...
                      > Hi, Amy:
                      >
                      > Thanks for the tip. After a few more fixings, I could see the results
                      > now by
                      > using a navigate(url) function and see the output, as in the code below
                      > shows.
                      >
                      > However, when I execute the Flex application, I get no updated result
                      > display on the application itself according to the input. I get no errors
                      > either. Does this mean that I have errors in my EventListeners lines? And,
                      > are
                      > there specific functions I should look into to get this to work?

                      is the actual content of your httpResult
                      //some processing
                      or do you actually do some processing there?

                      If you don't take the result and do anything with it, then you might as well
                      not have made the call.


                      • 8. Re: Post Variables Using Actionscript
                        alice_data Level 1
                        Hi, Amy:

                        Yes, I did mean to do something with the code, but since that snippet was working in the first place, that is why I did not put it here.

                        My revised version is in the edited version above. It looks like everything is finally working.

                        Thanks a lot.

                        Alice
                        • 9. Re: Post Variables Using Actionscript
                          Level 7

                          "alice_data" <webforumsuser@macromedia.com> wrote in message
                          news:gea5h9$kri$1@forums.macromedia.com...
                          > Hi, Amy:
                          >
                          > Yes, I did mean to do something with the code, but since that snippet
                          > was
                          > working in the first place, that is why I did not put it here.
                          >
                          > My revised version is in the edited version above. It looks like
                          > everything
                          > is finally working.
                          >
                          > Thanks a lot.

                          You're welcome :-)