0
votes

I have another problem with an acrionscript swf file. I'm reading some text from a CSV file. I create the fla file and when I test it in the animate editor it works and I can see all the text inside the CSV file into a TextField. If I export the .swf and run it with Adobe Flash Player 11.4 r402 I can't see the text that there is in the CSV File. I created this fla file made up of one photogram in which I wrote this code:

import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.filesystem.*;
import flash.text.TextField;

var pathToFile:String = File.applicationDirectory.resolvePath('ex.csv').nativePath;

var requestedFile:URLRequest = new URLRequest(pathToFile);

var myTextField:TextField = new TextField();

myTextField.autoSize = TextFieldAutoSize.LEFT;

var documentLoader = new URLLoader();

documentLoader.addEventListener(Event.COMPLETE, onload);

documentLoader.load(requestedFile);

function onload(evt:Event):void
{
  myTextField.text = evt.target.data;
  addChild(myTextField);
}

I get this error if I try to open the swf file in a broswer:

SecurityError:[SecurityErrorEvent type ="securityError" bubbles = false cancelable = false evenPhase=2 text="Error#2048"

How can I make the .swf file work? Is there a way to read data from a CSV file into a .swf file?

Thank you to everybody!

2
Are you getting an error message? If you are, please edit your question to include the details of your error. If you are compiling for AS3 (eg. you chose 'ActionScript 3' project in FlashPro/AnimateCC, then as Organis points out in their answer you can't use the File class (it should throw a compiler error, unless you chose an AIR template when you created your .fla) - BadFeelingAboutThis

2 Answers

2
votes

Package flash.filesystem.* is AIR runtime package. Flash IDE emulates AIR runtime while testing so it works, but Flash Plugin and Flash Projector runtimes do not support these classes.

Option 1: publish AIR application.

Option 2: avoid using AIR classes, to load a data file from the same folder where SWF is you need to parse SWF URL:

// Objtain SWF URL.
var applicationPath:String = loaderInfo.url;

// Figure / slash or \ backslash is used as folder separator.
var systemSlash:String = (applicationPath.indexOf("\\") > -1)? "\\": "/";

// Remove SWF name from URL.
var aSplit:Array = applicationPath.split(systemSlash);
aSplit.pop();
aSplit.push("");
applicationPath = aSplit.join(systemSlash);

// Now applicationPath contains full path to the folder where SWF is.
// Use it wisely!
1
votes

This is most likely a sandbox issue (security error).

To know what's going on, you should always listen for errors (instead of just COMPLETE) when you use asynchronous classes like URLLoader.

Add the following listeners in addition to your complete listener:

documentLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError); 
documentLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); 

And add the respective handler methods:

function onIOError(e:IOErrorEvent):void {
    //file not found, the event (e) will tell you the path it was trying to load and other details
    trace(e);
    //alert the user there was a problem
}

function onSecurityError(e:SecurityErrorEvent):void {
    //file was not allowed to load, sandbox issue
    trace(e);
    //alert the user there a problem
}

If you are indeed getting a security/sandbox error as I suspect, make sure you are publishing with the correct security sandbox setting.

Go to your publish settings file -> publish settings.

You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default access local only (if your CSV is coming from a server).