|
| test
 |
 |
|
|
|
 |

11-04-2008, 09:02 AM
|
|
|
Post Variables Using Actionscript
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.
private var request:HTTPService;
public function useHttpService(parameters:Object):void {
var request:URLRequest = new
URLRequest("http://192.168.10.62/simulation.php");
request.method = URLRequestMethod.POST;
request.data.population = "population";
request.data.market_capture = "market_capture";
request.data.simulation_length= "simulation_length";
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, function(event:Event):void {
trace("finished sending and loading: "+ loader.data);
});
loader.load(request);
}
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
"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?
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
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?
Thanks in advance.
Alice
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
"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
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
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/h.../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?
Thanks for your help.
Alice
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
"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/h.../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.
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
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?
Thanks again for your help.
private var request: URLRequest;
private var urlLoader:URLLoader;
public function runService(parameters:Object):void {
var url:String = "http://localhost/simulator.php";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.population=population.text;
request.data = variables;
request.method = URLRequestMethod.POST;
urlLoader = new URLLoader();
urlLoader.addEventListener("result", httpResult);
urlLoader.addEventListener("fault", httpFault);
urlLoader.load(request);
currentState="Result";
}
private function httpResult(e:ResultEvent):void {
//some processing
}
private function httpFault(e:FaultEvent):void {
Alert.show(e.message.toString(),"Error Occurred!");
}
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
"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.
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
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
|

11-04-2008, 09:02 AM
|
|
|
Re: Post Variables Using Actionscript
"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 :-)
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|