views:

934

answers:

4

I have an .aspx page that generates thumbnails. It takes an ID and returns an image with response Content-Type: image/jpeg.

How do I display this image in Flex?

A: 

Take a look a Loader

var loader:Loader = new Loader();
loader.load(new URLRequest("http://www.yoursite.com/yourasp.aspx?img=01001"));
addChild(loader);
ForYourOwnGood
+1  A: 

I believe this should work:


<mx:Image source="http://localhost/webform.aspx?ID=1"/>

You can obviously set the source in ActionScript or make the URL a bindable string so that you can pass in the ID.

mmattax
This approach won't quite work as described, since @Embed is a compile-time directive. But the concept correct.
Christian Nunciato
Yes, you are correct...thanks.
mmattax
+1  A: 

Generally you use the Image tag, and provided you're setting the response headers and encoding the bytes properly on the server (and you're working within the security sandbox), you should just be able to set the source property of that tag (it need not be @Embed-ded), and be done:

<mx:Image source="http://someurl.com/myimagegenerator.php?id=123" />

Are you having a problem with that approach, or is it just a general-information question?

Christian Nunciato
A: 

Now here's one for you. I'd like to do the opposite. I have a grails application that will be rendering an html page into a pdf file and I have a flex application sitting on a server that is going to accept REST parameters and construct a graph based on the parameters (which will be formatted in JSON). What I want to do is make a call to the flex app with my parameters and have the flex app create the graph, render a JPEG of the graph, then send an image back to grails. In other words, I want to put an HTML img src="http://flex-app-location/graphing-tool.swf?param=1&amp;param=2&amp;param=3"/ that will render the image directly to the page so that my PDF Plugin in grails will render it into the PDF.

I know how to render the image in Flex but I don't know how to push this image back over HTTP so that it can be rendered as image data. Any suggestions?