0

I have a developed a application that allows users to draw simple images on a canvas. The name of the movieclip(canvas) is canvas_mc.

I need to save this drawing on the server using php. I have to convert the movieclip (canvas_mc) into png and jpeg and save it. I have successfully save it on local drive using some classes available in

http://www.flashandmath.com/advanced/smoothdraw/index.html

How can I save it on server using PHP. I have been asked to use the post method. If possible give me the code also as I just moved into programming from design :-)

0

1 Answer 1

2

Not sure about how to convert your image into data and such, but here's a class I have lying around that you can use to transfer data to a PHP script (which can from there insert the data into a database).

package
{
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.events.Event;

    /**
     * @author Marty Wallace
     * @version 1.00
     */
    public class PHPData extends Object
    {
        /**
         * Sends data to a PHP script
         * @param script A URL to the PHP script
         */
        public function send(script:String, vars:URLVariables):void
        {
            var req:URLRequest = new URLRequest(script);

            req.data = vars;
            req.method = URLRequestMethod.POST;

            var loader:URLLoader = new URLLoader();
            loader.load(req);

            // listeners
            loader.addEventListener(Event.COMPLETE, _complete);
        }

        /**
         * Called when a response has been received from a PHP script
         * @param e Event.COMPLETE
         */
        private function _complete(e:Event):void
        {
            var vars:URLVariables = new URLVariables(e.target.data);

            var i:String;
            for(i in vars)
            {
                trace(i + ": " + vars[i]);
            }

            e.target.removeEventListener(Event.COMPLETE, _complete);
        }
    }
}

Use:

var php:PHPData = new PHPData();
var vars:URLVariables = new URLVariables();

vars.imagedata = your_image_data;

php.send("your_php_script.php", vars);
Sign up to request clarification or add additional context in comments.

6 Comments

I understand after some searching that I can convert my MovieClip into ByteArray and send it. I found the code for conversion var buffer:ByteArray = new ByteArray(); buffer.writeObject(MOVIE_CLIP_HERE); buffer.position = 0; buffer.writeBytes(...); I found it here. stackoverflow.com/questions/1482053/… But what should be argument of writeBytes function. The documentation says it 'The ByteArray object'. But I just created it I understand.I think then using the class and putting vars.imagedata = buffer; the job will be done.
Cool, if that's the case then you should be able to send that over to PHP using the above.
What I cant figure out is what should be the 1st argument of the writeBytes function in var buffer:ByteArray = new ByteArray(); buffer.writeObject(MOVIE_CLIP_HERE); buffer.position = 0; buffer.writeBytes(...);
Not sure, never used a ByteArray before. Check Adobes livedocs (livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3) to have a good look at arguments for methods and so on.
Thank you so much Marty. You were so helpful.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.