I'm working on an application and we are using Flash to add an interface. During the initialize the app loads in a config file with references to image paths. When I use the Loader and URLRequest classes to load those images the path is not working and it's causing issues. Based on everything I've researched my code should work. I have a trace that outputs "source/icons/default.png" which is the correct relative path for the external image and loading the image works, but I need to use a variable to set the image path. Setting the URLRequest with a variable, new URLRequest("source/icons/" + default.png);, causes it use a full file path that looks wrong and reports a 2035 error. Is there something that I'm doing wrong? I'm not sure what to do at this point. I've verified the file exists and I've verified the path of the file.
Trace Ouput:
source/icons/default.png
Error Output:
[CompanionStatus] Error occurred while loading bitmap
[CompanionStatus] 2035 : Error #2035: URL Not Found. URL: file:///C|/Users/devtrooper/Desktop/project/source/icons/default.png
It looks like flash is replacing the colon (:) near the drive letter with a pipe (|) and I'm not sure if that is the issue.
Here is my method for loading images:
private function getBitmapData(nameString:String, imagePath:String):void{
try{
var bitmapDataFunction:Function = addBitmapDataToDictionary(nameString);
var path:String = ICON_FOLDER_PATH + imagePath;
var loader:Loader = new Loader();
var urlRequest:URLRequest = new URLRequest("source/icons/" + imagePath);
trace("URLRequest.url " + urlRequest.url);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, bitmapDataFunction, false, 0, true);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleBitmapDataError, false, 0, true);
loader.load(urlRequest);
} catch (e:Error) {
log("Error occured while trying to load image data");
log(e.name + " : " + e.message);
}
}
you can use File method instead of urlRequest method like this:
var urlPath:String="";
var picFile:File = File.desktopDirectory.resolvePath("source/icons/default.png");//you can use applicationDirectory,applicationStorageDirectory,userDirectory,doumenntDirectory and ...
if (picFile.exists == true) {
urlPath = picFile.url;
}
Related
I have an Adobe Air Application that would open an csv file on Mac. I am getting an error which I am not getting with the same app for Windows, so I am thinking something about file locations, etc is amiss. Here is the code:
var file: File = File.applicationStorageDirectory;
file = file.resolvePath("A&P plans");
file.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
function filesSelected(event: FileListEvent): void {
//trace(event.files.length);
fileList = new Array();
fileNames = new Array();
for (var i: uint = 0; i < event.files.length; i++) {
fileList.push(event.files[i].nativePath);
trace("name of file loaded is ", event.files[i].name, "where :", event.files[i].nativePath);
}
}
var urlRequest: URLRequest = new URLRequest(fileList[0]);
function openCSVFile():void{
csv = new CSV(urlRequest);
csv.addEventListener(Event.COMPLETE,onComplete);
csv.addEventListener(IOErrorEvent.IO_ERROR, onErrorOpening);
function onComplete(event:Event):void{
trace("file open successful");
}
function onErrorOpening(event:IOErrorEvent):void{
trace ("error opening file");
}
}
The URLRequest trace shows the location where it should be, so the app knows where to look, and it does find the file. Here is the result of the trace :/Applications/myApp.app/Contents/Resources/A&P plans/majors/NationalLeague.csv. Yet, instead of the completeEvent showing the trace, the errorEvent is inovked. Any ideas where to look for the issue? The file does not have any weird characters in its name or anything. Tracing the error shows the following: Error #2032: Stream Error. Thanks
Quite possibly the ampersand and the space in 'A&P plans' might be troublesome.
Try removing/changing those.
I am using the following loadmodel function to load a json into html. (jsons were exported from Blender)
(function init(){
console.log("Init")
loadmodel('object1');
loadmodel('object2');
loadmodel('object3');
loadmodel('object4');
requestAnimationFrame(rotate);
})();
function loadmodel(str){
var json = "{% static 'three/' %}" + str + '.json.gz';
var loader = new THREE.JSONLoader();
loader.load(json, function(geometry, materials){
alfaromeo = new THREE.Mesh(
geometry, new THREE.MeshFaceMaterial(materials)
);
alfaromeo.name = str;
names.push(str);
scene.add(alfaromeo);
});
}
My problem is that I have more than one json to load and when I call this function for each json, only the first one is getting loaded and the others are not. The same code is working well in my friends computer - all the jsons are loading well.
Is there anything I am missing?
As one of the comments stands, the JSONLoader is asynchronous, so the best way to be sure you are rendering what has been already downloaded is to trigger the render once you have download the JSON file in your onLoad method.
Actually what I would recommend is that you call just once to loadmodel to load just one JSON file, after the first download trigger again a new download, the last of your JSON file download should then trigger the scene render.
(function init(){
console.log("Init")
loadmodel('object1');
//this should be called when your last object has been added to the scene
//requestAnimationFrame(rotate);
})();
Just a quick n dirty example from your code:
function loadmodel(str)
{
var json = "{% static 'three/' %}" + str + '.json.gz';
var loader = new THREE.JSONLoader();
loader.load(json, function(geometry, materials){
alfaromeo = new THREE.Mesh(
geometry, new THREE.MeshFaceMaterial(materials));
alfaromeo.name = str;
names.push(str);
scene.add(alfaromeo);
// Add here proper logic to load next model...
if(str=="object1")
loadmodel("object2");
else if()...
else
{
console.info("done with all downloads!");
requestAnimationFrame(rotate);
}
});
}
There are images inside of folder names like Slide1.jpg,Slide2.jpg, until Slide20.jpg. But program doesn't know how many images inside of folder. I dont want to count them also.(lets say total number of images = 100). But when press nextBtn until Slide20.jpg program will take:
Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never
Completed
When program Catches that error logically, it means there is no file name like Slide21.jpg. Which means total image number is 20. I want to go back when take at first time that error. Thanks for any advice
var totalImages=100;
var imageNumber=1;
var myLoader:Loader = new Loader();
//************LOADING IMAGES TO STAGE********************//
//elearningau.com/nondynamic/
var myRequest:URLRequest = new URLRequest("http://elearning.com/upandshow/Images/Slide"+imageNumber+".JPG");
myLoader.load(myRequest);
addChildAt(myLoader,1)
rightButton.addEventListener(MouseEvent.CLICK, nextImage);
function nextImage(event:MouseEvent){
if(imageNumber<totalImages)
{
imageNumber++;
} else {
imageNumber = 1;
}
reload();
}
function reload(){
removeChild(myLoader);
myRequest= new URLRequest("http://elearning.com/upandshow/Images/Slide"+imageNumber+".JPG");
myLoader.load(myRequest);
addChildAt(myLoader, 1);
}
You need to listen for errors:
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
function ioErrorHandler(event:IOErrorEvent):void {
// this means there was an error - do whatever you want
}
I have an issue with Workers in AIR : when I try to open a file in a non-primordial Worker, I get a Security error. When I try the same code in the primordial Worker, it works well.
I load another swf and pass its bytes when creating the second Worker.
First, I tried with URLLoader (code in 2nd worker) :
// Loading XML test
var loader:URLLoader = new URLLoader(new URLRequest('app:/config/generator/galaxy.xml'));
loader.addEventListener(Event.COMPLETE, function(evt:Event):void
{
// Trace
CEThreadDebugger.log(XML(loader.data).toString());
});
loader.addEventListener(IOErrorEvent.IO_ERROR, function(evt:IOErrorEvent):void
{
CEThreadDebugger.log(evt.text, CEThreadDebugger.ERROR);
});
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(evt:SecurityErrorEvent):void
{
CEThreadDebugger.log(evt.text, CEThreadDebugger.ERROR);
});
I get this error :
[LOG]ERROR->Error #2048: Security sandbox violation: app:/SombresCieux.swf cannot load data from app:/config/generator/galaxy.xml.
Then I tried with File :
var file:File = File.applicationDirectory.resolvePath('config/generator/galaxy.xml');
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
var xml:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
And I get this error (my code is in _mainToWorker method) :
[LOG]INFO->Error #0 : SecurityError -> file
SecurityError: file
at flash.filesystem::File$/initAppResourceDir()
at flash.filesystem::File$/get appResourceDirectoryPath()
at flash.filesystem::File$/get applicationDirectory()
at generator::Generator/_mainToWorker()
at engine.generic.system.concurrency::CEThreadMain/Evt_mainToWorker()
I noticed that the error comes from this line alone :
var file:File = File.applicationDirectory.resolvePath('config/generator/galaxy.xml');
So it works in the primordial Worker (main app), but not in the threads...
Can't the Workers access system's files nor load any file ? It's a quite huge limitation...
Thanks for the replies !
public function createWorker(swf:ByteArray,
giveAppPrivileges:Boolean = false):Worker
giveAppPrivileges:Boolean (default = false) — indicates whether the worker should be given application sandbox privileges in AIR. This parameter is ignored in Flash Player
Alright so I am using the stencyl engine to make a flash game, and I wanted to upload an Swf file. The problem is I keep getting an error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at _247gamesonline_fla::bn0_Symbol1_2/frame1()
Now I went to that part of the fla file that had the error, and tried to see what was wrong, but could not figure it out. Here is the code:
stop();
var doMain:String = this.stage.loaderInfo.url;
var doMainArray:Array = doMain.split("/");
var domainname = doMainArray[2];
var gamename = "nameofgame";
var linktodjp = "http://www.247gamesonline.com/? p=cat&order=2&tag=puzzle&utm_medium=partnergame&utm_campaign=" + gamename + "&utm_source=" + domainname + "&utm_content=partnergame";
var linktodjpfb = "http://www.facebook.com/connect/uiserver.php?app_id=201345053230176&next=http://www.3j.com/processfacebook.php%3Futm_source%3D" + domainname + "%26fgamet%3D76&display=page&cancel_url=http%3A%2F%2Fwww.3j.com%3F3Futm_source%3D" + domainname + "&locale=en_US&return_session=1&session_version=3&fbconnect=1&canvas=0&legacy_return=1&method=permissions.request&perms=publish_stream,offline_access,email,user_birthday,user_interests,read_friendlists";
buttonplay.addEventListener(MouseEvent.CLICK, playlogonow);
logo.addEventListener(MouseEvent.CLICK, gotowebsite);
logo.buttonMode = true;
stop();
function playlogonow(e:Event) {
logo.play();
gotoAndStop(2);
return;
}
function gotowebsite(e:Event) {
navigateToURL(new URLRequest(linktodjp));
return;
}
Also in another part of the code it simply says
on (release) {
_root.play();
}
Help anyone?
Difficult to say by having that code only. Whatever, I would recommend to put many trace statements there to figure out what variable actually equals null and leads to that exception. Then act accordingly.