views:

128

answers:

2

Can I load something using AS3/SWF and then create a DOM element using javascript to display the loaded data, without having the browser to load the same data twice?

A: 

Yes, but it's not easy. You would have to convert the image to (for example a base64) string using a custom function looping through all the pixels of the bitmapdata, then send it to the webpage using an external interface, and then convert it back, either using the base64 to set the image url, or using Canvas to build the image manually from the pixels.

Marius
sounds like a challenge! any methods/classes that can point me in the right direction?
David
A: 

Perhaps I've missed something in what you've said but wouldn't it be quite easy to use the FileReference upload() method to send the file to a php script which then moves the file to the desired location on the server. If you wanted to have the image display in html without a new page load you could (I'm not too familiar with JS but I assume this is possible -> ) periodically check to see if your desired file is in the desired location. You could call a js function through ExternalInterface to tell the html page to expect this file and to check for it.

I've not tested this method so I can guarantee there are no flaws in it but it's the way I would attempt first. I'm assuming you're sending an image but it would work fine for any other file.

Oliver
If I use the FileReference upload() method, The image would have to be tranfered twice; location -> server -> client. I would like to do it once; location -> client using AS3. Then have the image data displayed as an <img> tag. So I guess I need to decompile the image in actionscript and send as base64 data to the JavaScript, then create an IMG element and attach the data as a src attribute.
David