PDA

View Full Version : import files to library with jsfl


multicereal
02-27-2006, 01:51 PM
i want to import a file (mp3 or jpg) into my library. i made this code, it should import a file with the same name as the FLA and which is in the same document.


var dom = fl.getDocumentDOM();
dom.getTimeline().addNewLayer("Sound", "normal", true);
var fileName = flash.documents[0].name;
var filePath = flash.documents[0].path;

//get filename without extention:
aFile = fileName.split(".");
//get filepath without filename:
aPath = filePath.split(fileName);

//make a valid path:
myFile = aPath[0]+""+aFile[0]+".mp3";

//convert to valid URI
uri = encodeURIComponent(myFile);

dom.importFile(uri,true);

(when you run the command, make sure there's only one document open --> that is "documents[0]")

anyway, it should work but it says: "The import did not finish because an unknown error occurred" and "One or more files were not imported because there were problems reading them". The files are just basic mp3's or jpg's, no problem there...

anyone done this before???

hangalot
02-27-2006, 02:57 PM
yeah man. i have spent months on merging libraries with some success.
anyway here is my code:
http://londonmmug.org/showthread.php?t=218

its the merge tool.zip

multicereal
02-27-2006, 04:07 PM
wow that's a huge project.

at first glance it doesn't appear to do the trick for external files (? correct me if i'm wrong). i will certainly take a look at it, maybe i can dump all the files i need in one library and them get them out when needed, that may help!

do you think that what i tried above is a bug? or did i do something wrong? (i've only just begun exploring the jsfl-beast, so i'm not yet familliar with it's features....)

hangalot
02-27-2006, 04:08 PM
sorry i misread you. external files... google peter elst and jsfl, there are limitations. that thing is meant to merge libraries from different fla's. it was early when i replied ;)

multicereal
02-28-2006, 08:49 AM
i found it! i was passing a wrong uri. it should be something like this "file:///c|/sound.mp3" and i tried to pass "file:///c:/sound.mp3", notice the difference! also it isn't necensary to do this: encodeURIComponent(myFile);
so basically take the path you want and replace ":" with "|" and "\" with "/" and than add "file:///"
hope this helps for someone! it certainly does the trick for me!