Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it is possible. First you convert the displayObject in wich the design is into a byteArray wich you send to php. where you create an image using the imagecreatefromstring() function see: <a href="http://lv.php.net/imagecreatefromstring" rel="nofollow">http://lv.php.net/imagecreatefromstring</a>.</p> <p>Example AS3</p> <pre><code>public function displayObjectToPNG(displayObject:*, scale:Number = 1):ByteArray { var bmpData:BitmapData=new BitmapData(displayObject.width, displayObject.height, true, 0xFFFFFF); bmpData.draw(displayObject); var byteArray:ByteArray = PNGEncoder.encode(bmpData); return byteArray; } public function encodeFile(byteArray:ByteArray):Base64Encoder { var base64:Base64Encoder = new Base64Encoder(); base64.encodeBytes(byteArray); return base64; } public function saveFile(encodedFile:Base64Encoder, scriptLocation:String):void { var data:URLVariables = new URLVariables(); data.fileData = encodedFile; var request:URLRequest = new URLRequest(scriptLocation); request.method = URLRequestMethod.POST; request.data = data; var loader:URLLoader= new URLLoader(); loader.addEventListener(Event.COMPLETE, function(e:Event):void {fileSaved(loader);}); loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatus); loader.addEventListener(IOErrorEvent.IO_ERROR, ioError); _fileSavesInProgress.push(loader); try { loader.load(request); } catch (e:*) { trace("an error occured of type", e); } } </code></pre> <p>Implement like this (this is the code you would execute when the user clicks the button):</p> <pre><code>saveFile(encodeFile(displayObjectToPNG(sprite)), "http://www.your.domain/php/sendMail.php"); </code></pre> <p>Your php file will look something like this.</p> <pre><code>&lt;?php $png = imagecreatefromstring(base64_decode($fileData)); function mail_attachment($to, $subject, $message, $from, $file) { $content = chunk_split($file); $uid = md5(uniqid(time())); $from = str_replace(array("\r", "\n"), '', $from); // to prevent email injection $header = "From: ".$from."\r\n" ."MIME-Version: 1.0\r\n" ."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n" ."This is a multi-part message in MIME format.\r\n" ."--".$uid."\r\n" ."Content-type:text/plain; charset=iso-8859-1\r\n" ."Content-Transfer-Encoding: 7bit\r\n\r\n" .$message."\r\n\r\n" ."--".$uid."\r\n" ."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n" ."Content-Transfer-Encoding: base64\r\n" ."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n" .$content."\r\n\r\n" ."--".$uid."--"; return mail($to, $subject, "", $header); } mail_attachment("client", "subject", "your design", "your@company.com", $png); </code></pre> <p>Note that I have not tested this but I think this will be very close if not the solution. Good luck!</p> <p>[Edit] If you want to implement this solution in one function use the following AS3 code:</p> <pre><code>public function sendSprite(sprite:Sprite, scriptLocation:String):void { var bmpData:BitmapData=new BitmapData(sprite.width, sprite.height, true, 0xFFFFFF); bmpData.draw(sprite); var encodedFile:Base64Encoder = new Base64Encoder(); encodedFile.encodeBytes(PNGEncoder.encode(bmpData)); var data:URLVariables = new URLVariables(); data.fileData = encodedFile; var request:URLRequest = new URLRequest(scriptLocation); request.method = URLRequestMethod.POST; request.data = data; var loader:URLLoader= new URLLoader(); loader.addEventListener(Event.COMPLETE, spriteSend); loader.addEventListener(Event.OPEN, traceEvent); loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, traceEvent); loader.addEventListener(IOErrorEvent.IO_ERROR, traceEvent); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, traceEvent); loader.addEventListener(ProgressEvent.PROGRESS, traceEvent); try { loader.load(request); } catch (e:*) { trace("an error occured of type", e); } function traceEvent(e:*):void { trace(e); } function spriteSend(e:Event):void { trace(e, "\n sprite succesfully send \n"); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload