开发者

How to pass values from Python to flex

I am calling Python script from flex using HTTP se开发者_StackOverflow社区rvice. How can I send back some values from python to flex app?

Thanks


Using HTTPService, many people will send back XML. Sometimes they'll send back plain text. In your result handler, you should get the text returned from the service call as event.result.

Your result handler may look something like this, if you were to return XML:

public function onHTTPServiceResult(event:ResultEvent):void{
 var myResult : XML = event.result as XML
 // process XML in some manner
}

If you were to return plain text, it may look something like this:

public function onHTTPServiceResult(event:ResultEvent):void{
 var myResult : String = event.result as String
 // do something with the String value here
}

The only time I've used the latter approach is if the return value is really simple, like a Boolean value (true or false). The only time I use XML is when I have no control over what the remote service returns. If at all possible I try to use an AMF Gateway; which will automatically translate server side objects into ActionScript objects.

I can assume that you know how to create a service in Python to output XML or text data.


It's nothing too complex you could try to output xml from Python, then parse that from Flex.

If you're dealing with a lot of data that might generate a large xml file, give PyAMF a try.

How to pass values from Python to flex

HTH


That really depends on how the Python backend is done, ie. what HTTP server code is handling the request sent from Flex. Here's a link to the Python http.server docs, but if the web service is done using something else, such as Django then have a look at their docs, or have a look at `George Profenza' PyAMF suggestion. I've used the PHPAMF library myself and it makes communicating quite easy, supposedly the PyAMF will do so as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜