Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:57:20+00:00 2026-06-09T21:57:20+00:00

I’m doing a project in AS3 where the user can design something and order

  • 0

I’m doing a project in AS3 where the user can design something and order it after. The design is exported to a PDF, PNG and XML. These files I want to save on the server. On MAMP it all works and I get the HTTPStatus 200, note that I run my SWF from MAMP but the php-script is successfully accessed on the remote server and the files are written to the Remote server with succes as well. However when i copy the SWF to the remote server, the files do not save and I get a HTTPStatus 0.

In the class that I use (see AS3 code below) I use a URLLoader to get to the following one line php script:

<?php file_put_contents($_POST['location'] . $_POST['fileName'], base64_decode($_POST['fileData']));

Here the AS3 class:

public class ServerConnection extends Sprite
{
    private var _files:Array = new Array();
    private var _fileNames:Array;
    private var _fileLocation:String = "";
    private var _scriptLocation:String;

    private var _fileSavesInProgress:Array = new Array();

    public function ServerConnection(scriptLocation:String = null, files:Array = null, fileNames:Array = null)
    {
        if (scriptLocation) setScriptLocation(scriptLocation);
        if (files) setFiles(files);
        if (fileNames) setFileNames(fileNames);
    }


    public function encodeFiles():void {
        for(var i:uint = 0; i < _files.length; i++) {
            _files[i] = encodeFile(_files[i]);
        }
    }
    public function encodeFile(byteArray:ByteArray):Base64Encoder {
        var base64:Base64Encoder = new Base64Encoder();
        base64.encodeBytes(byteArray);
        return base64;
    }

    public function saveFiles(location:String = null):void {
        if (location) setFileLocation(location);
        for(var i:uint = 0; i < _files.length; i++) {
            _files[i] = saveFile(_files[i], _fileNames[i]);
        }
    }
    public function saveFile(encodedFile:Base64Encoder, fileName:String = "test"):void {
        var data:URLVariables = new URLVariables();
        data.fileData = encodedFile;
        data.fileName = fileName;
        data.location = _fileLocation;
        this.dispatchEvent(new DebugEvent(DebugEvent.MESSAGE, "@serverConnection: a save file request was made for " + 
            fileName + "\n" +
            "url: " + _fileLocation + "\n" +
            " scriptLocation: " + _scriptLocation + "\n"
        ));

        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:*) {
            this.dispatchEvent(new DebugEvent(DebugEvent.MESSAGE, "@serverConnection: error:* = " + e + " \n"));
        }

        //navigateToURL(request);
    }

    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 xmlToByteArray(xml:XML):ByteArray {
        var byteArray:ByteArray = new ByteArray();
        byteArray.writeUTFBytes(xml);
        return byteArray;
    }

    public function setScriptLocation(url:String):void {
        _scriptLocation = url;
    }

    public function setFileLocation(url:String):void {
        _fileLocation = url;
    }

    public function setFiles(array:Array, encode:Boolean = true):void {
        for each(var file:* in array) {
            for each(var type:XML in describeType(file).extendsClass.@type) { 
                if (type == "flash.display::DisplayObject") file = displayObjectToPNG(file);
            }
            if (typeof(file) == "xml") {
                file =  xmlToByteArray(file);
            }

            _files.push(file);
        }
        if (encode) encodeFiles();
    }

    public function setFileNames(array:Array):void {
        _fileNames = array;
    }


    // EVENTS
    private function httpStatus(e:HTTPStatusEvent):void {
        this.dispatchEvent(new DebugEvent(DebugEvent.MESSAGE, "@serverConnection: status = " + e.status + " \n"));
    }

    private function ioError(e:IOErrorEvent):void {
        this.dispatchEvent(new DebugEvent(DebugEvent.MESSAGE, "@serverConnection: IOErrorID = " + e.errorID + "  Message: "+ e.text + " \n"));
    }

    private function fileSaved(loader:URLLoader):void {
        this.dispatchEvent(new DebugEvent(DebugEvent.MESSAGE, "@serverConnection: file save completed. " + (_fileSavesInProgress.length -1) + " files to go \n"));
        _fileSavesInProgress.splice(_fileSavesInProgress.indexOf(loader), 1);

        if (_fileSavesInProgress.length == 0) {
            filesSaved();
        }
    }

    private function filesSaved():void {
        this.dispatchEvent(new DebugEvent(DebugEvent.MESSAGE, "@serverConnection: files saved \n"));
        this.dispatchEvent (new ClassAttributesLoaded(ClassAttributesLoaded.CLASS_ATTRIBUTES_LOADED));
    }

}

which I implement like this

    var s:ServerConnection = new ServerConnection(
    CONSTANT.SAVE_FILE_SCRIPT_LOCATION, 
    [currentTemplate.getXML(), exampleTemplate, pdf.save(Method.LOCAL)], 
    [CONSTANT.PACKAGE_ID + ".xml", CONSTANT.PACKAGE_ID + ".png", CONSTANT.PACKAGE_ID + ".pdf"]
);
s.addEventListener(DebugEvent.MESSAGE, writeToDebug);
s.addEventListener(ClassAttributesLoaded.CLASS_ATTRIBUTES_LOADED, exit);
s.saveFiles(CONSTANT.RELATIVE_FILE_DIRECTORY);

When I change loader.load(request); to navigateToURL(request); the code does work. on the local and remote server. for obvious reasons I can’t use navigateToURL in this case. I do think that the fact that navigateToURL does work and loader.load(request) doesn’t say something about the problem… but what?

I’m kind of stuck on this and would appreciate help.
Thanks in advance!

PS: for testing I have set the permission of the remote DIR to 777. Furthermore the files are successfully saved from MAMP to Remote anyhow as stated before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:57:21+00:00Added an answer on June 9, 2026 at 9:57 pm

    Solution

    After long research I have found the solution:
    Adding the following crossdomain.xml to the root of my webserver (www.mysite.nl/).

    <?xml version="1.0" ?>
    
    <cross-domain-policy>
        <site-control permitted-cross-domain-policies="master-only"/>
        <allow-access-from domain="*.mydomain.com" to-ports="*"/>
        <allow-http-request-headers-from domain="*.mydomain.com" headers="*"/>
    </cross-domain-policy>
    

    This is not secure so if you want to use this solution please change ‘mydomain.com’ to the specific domain you want to allow. So that fixed it.

    How I got to the answer

    I was able to catch the error using the following code:

    loader.addEventListener(IOErrorEvent.IO_ERROR, handleSecurityError);
    

    The error returned was the following: [SecurityErrorEvent type=”securityError” bubbles=false cancelable=false eventPhase=2 text=”Error #2048″]

    Note that usually the error contains: [SecurityErrorEvent type=”securityError” bubbles=false cancelable=false eventPhase=2 text=”Error #2048: Security Sandbox Violation : http://www.domain-a.com/url/file-a.swf can not load data from http://www.domain-b.com/url/file-b.swf“]

    This error is usually solved by loading a security policy. check out this link about how to use security policies: http://kb2.adobe.com/cps/142/tn_14213.html

    However in this case the url accessed is within the same domain. (NOTE: same folder :D) So initially I thought this was irrelevant as there is no other domain contacted. But after searching for a week I got so desperate I tried it any how.

    So adding a crossdomain.xml to the root of my server solved the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.