0

I am currently creating a user interface in flash to go on a website in which clients can create their own design for a bespoke product. The idea is that we want them to be able to create their design and using the form at the bottom, sent the design to us by saving it as a jpeg and attaching it to an email through PHP.

Is there any possible way to do this?

3 Answers3

1

If you using a Adobe AIR, It's possible directly email send to your email domain without PHP.

When I did not know PHP, only using a flash(as3.0) and e-mail sent in was very difficult to implement. However, without knowing the server side, such as php using Adobe Air, i can be easily implemented.

I gladly recommend using a Adobe AIR send to mail with airxmail frameworks.

this is a site: airxmail

this is a documentaion : airxmail documetation

bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
1

You can draw the stage on a bitmapdata and send that bitmap to php for mail purpose.

Check this site out for an example how to do it saving as3 displayobject as png.

The trick is to draw the stage on bitmapdata using the draw function in bitmapdata. Then send this bitmapdata to php for mail purpose in an attachment.

automaticoo
  • 868
  • 7
  • 24
  • I think that is just what I'm after, thank you very much. How would I go about making it draw the stage when the submit button is clicked? This is the script for the button so far; http://pastebin.com/CSBRh4jt – Jakk Smith Aug 08 '12 at 13:31
  • The easiest way is to first send your bitmapdata/image and if that request is done send rest of the data to mail.php which will take the earlier saved image and mail it. I would first use this solution http://stackoverflow.com/questions/597947/ and then if that request is done send the rest of the data to php. In php you can take the uploaded image and add it as attachment – automaticoo Aug 08 '12 at 13:48
1

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: http://lv.php.net/imagecreatefromstring.

Example AS3

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);
        }
    }

Implement like this (this is the code you would execute when the user clicks the button):

saveFile(encodeFile(displayObjectToPNG(sprite)), "http://www.your.domain/php/sendMail.php");

Your php file will look something like this.

<?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);

Note that I have not tested this but I think this will be very close if not the solution. Good luck!

[Edit] If you want to implement this solution in one function use the following AS3 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");
  }

}

SKuijers
  • 406
  • 7
  • 18
  • Pleasure :) I'm working on a similar project but I seem to have a different bottleneck :D. Good luck with your project! – SKuijers Aug 13 '12 at 10:10
  • I have just encountered a bit of a problem, I'm getting an error when I try to run the program as Flash(CS5.5) won't allow me to have multiple public functions; I've heard this is a fairly recent change and I was wondering if you knew any way to get round this? the project is very close to finished and this is more or less the final step :) – Jakk Smith Aug 22 '12 at 11:25
  • Would that mean that you use the timeline? I only use flashbuilder so I'm not familiar with Flash itself. I'll update the answer so all the AS3 code is in one function. BTW: did you get the PHP code to work? – SKuijers Aug 24 '12 at 08:25