CounterMarch Systems

proud to be geeks


We used to blog more before twitter came along.

Load image into Flash - without the loader!

Flex/Flash question for today!

We want to load an image in to our Flex app. That's simple if the images are in a web-accessible directory. We don't want to do that for "security" reasons.

So we thought we'd just do a little CFFILE manipulation on the server side and return the contents of the image file over the wire in a remoteObject call.

Flash has a bytestream class that we can clearly dump the file contents into...but where we're stuck is getting the data out of the bytestream and into a rendered image in Flash.

Can anyone help?

Comments
Phil Duba's Gravatar Steve. couldn't you use a .cfm file with a parameter to identify the image and load it like what a lot of folks do for renderring of files outside the webroot? Something like img src="getImage.cfm?image=product" where getImage.cfm does the whole cfcontent/cfheader manipulating along with a CFFILE read as binary? Shouldn't that return the image to Flash as if you were reading it directly?
# Posted By Phil Duba | 2/9/07 11:33 AM
Steve's Gravatar That would be great IF we chose to maintain session state on the server as well as the client. Gotta verify permissions before feeding back an image and I'm not going to send U/P over the wire in a form or url var.
# Posted By Steve | 2/9/07 11:38 AM
Phil Duba's Gravatar So I take it then all your communication is with RO calls and there is no session on the server?
# Posted By Phil Duba | 2/9/07 11:41 AM
Steve's Gravatar Yep.
# Posted By Steve | 2/9/07 11:43 AM
Graeme Wicksted's Gravatar Try looking at the BitmapData object. I believe it can take a stream of bytes. Then create a new instance of a Bitmap object passing in the BitmapData object. Then set the source property of your image to the Bitmap object instance.

This may be accomplished using the setPixels() function of the BitmapData class. It requires a rect and a ByteArray.

Hope this helps.
# Posted By Graeme Wicksted | 8/15/07 11:59 PM
Steve's Gravatar @Graeme: that's exactly what we ended up doing. Seems to be working well enough for our purposes now. Have to do some load testing to see if it holds up. Thanks for the suggestion!
# Posted By Steve | 8/16/07 8:16 AM
Lukas's Gravatar Steve can you share some hints how to do it - i have no idea about flash but i am stuck with exactly the same problem coz all our images are stored in sql server. So i can easily get the stream or the bitmap object in the asp page but then what?? how do i pass it to the flash? appreciate your help
# Posted By Lukas | 8/20/07 1:36 PM
Graeme Wicksted's Gravatar Hi Steve.

You may not need to do this if you can get at it from your ASP. Simply set the Image source property to the same one that your img tags in ASP are pointing to and it should load the image on its own at runtime.
# Posted By Graeme Wicksted | 9/30/07 2:01 PM
Graeme Wicksted's Gravatar Edit: sorry I meant to say Hi Lukas in my previous post.
# Posted By Graeme Wicksted | 9/30/07 2:02 PM

About the blog

7 years of outstanding software development

CounterMarch Systems is a professional consulting firm specializing in Adobe technologies with a special focus on higher education.

2771 Red Oak Circle
Bethlehem, Pennsylvania 18017
610.280.3455
Contact Us