Skip to main content
Known Participant
October 14, 2015
Question

Getting error while using string value got from db and used it for file path in AS3

  • October 14, 2015
  • 1 reply
  • 476 views

In my ActionScript project i'm getting error while using string value got from db and used it for file path

         var j:uint=0;
var xml:XML = new XML(DecryptXMLFile(GetXMLFilename(bookPath)));
ReadXMLData(xml);

private function GetXMLFilename(dirLocation:File😞File
  
{
  
var xmlFile:File;
  
var list1:Array = new Array();
  
var dirList:Array = dirLocation.getDirectoryListing();
  
for (var i:uint = 0; i < dirList.length; i++)
  
{
  
if (GetExtensionFromNativePath(dirList[i].nativePath) == "xat")
  
{
  
if(j==0)
  
DataManager.getInstance().sqlInsert( dirList[i].name, "R");
  
else
  
DataManager.getInstance().sqlInsert( dirList[i].name, "NR");
  j
++;
  
}
  
}

  
var path:String = DataManager.getInstance().getData().toString();
  trace
(path);
  xmlFile
= path;
  
return xmlFile;
  
}

  
private function DecryptXMLFile(file:File😞String
  
{
  
//Decode base64 string to png image
  
}

DB output is 0.xat

Error it shows as,

TypeError: Error #1034: Type Coercion failed: cannot convert "0.xat" to flash.filesystem.File. at com.reader::Reader/GetXMLFilename() at com.reader::Reader/StartPlayingBook() at com.reader::Reader/Init() at com.reader::Reader() at starling.core::Starling/initializeRoot()[/Users/redge/Dropbox/Development/starling/starling/src/starling/core/Starling.as:458] at starling.core::Starling/initialize()[/Users/redge/Dropbox/Development/starling/starling/src/starling/core/Starling.as:435] at starling.core::Starling/onContextCreated()[/Users/redge/Dropbox/Development/starling/starling/src/starling/core/Starling.as:691]

Even I changed the code as,

xmlFile= new File(path);

doesn't helps

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
October 14, 2015

use the resolvePath() method to convert a string to a file.

file=resolvePath('0.xat'); // where file has already been created and has the correct directory.

Known Participant
October 14, 2015

I can't directly use the 0.xat as path, it is stored in db and i'm retrieving data from db using path:String

if change the code as you said,

file = resolvPath(path);

Error is 1180:Call to a possibly undefined method resolvePath.

kglad
Community Expert
Community Expert
October 14, 2015

sorry, that was a typo.  use

file=file.resolvePath(yourdbstring); // where file has already been created and has the correct directory.