check if files exist on server?

2934
29
09-06-2010 05:01 AM
NatashaManzuiga
Regular Contributor
Hi, how can I test if an image files exist on server in Flex 3.0?

Thanks in advance
Tags (2)
0 Kudos
29 Replies
NatashaManzuiga
Regular Contributor
Naty,

   With the code you just posted you are attempting to load a PDF file into an image control which is not supported. There is no PDF viewer component in Flex by default.


Sorry it was just a sample...I corrected it...

Thanks.
Naty
0 Kudos
NatashaManzuiga
Regular Contributor
Sorry it was just a sample...I corrected it...

Thanks.
Naty


Hi Robert...I corrected it but it still doesnt work 😞
Is there another function to do this that work with PDF files?

Thanks,
Naty!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Naty,

   What is the string that you are passing in for the imgx? Is it the same as the nameBuilding?

public function IOErrorEventHandler(imgx:String):void {

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, ioErrorHandler);
var request:URLRequest = new URLRequest(imgx);
loader.load(request);
}
private function onComplete (evt : Event) : void
{
var nameBuilding:String = Building1.selectedItem.@dgn;
nameBuilding="CleanPrintA4/" + nameBuilding.toString().substr(0,nameBuilding.leng th-4) + ".pdf";
var u:URLRequest = new URLRequest(nameBuilding);
navigateToURL(u, "_blank");
}
private function ioErrorHandler(event:IOErrorEvent):void {

}
0 Kudos
NatashaManzuiga
Regular Contributor
Naty,

   What is the string that you are passing in for the imgx? Is it the same as the nameBuilding?

public function IOErrorEventHandler(imgx:String):void {

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, ioErrorHandler);
var request:URLRequest = new URLRequest(imgx);
loader.load(request);
}
private function onComplete (evt : Event) : void
{
var nameBuilding:String = Building1.selectedItem.@dgn;
nameBuilding="CleanPrintA4/" + nameBuilding.toString().substr(0,nameBuilding.leng th-4) + ".pdf";
var u:URLRequest = new URLRequest(nameBuilding);
navigateToURL(u, "_blank");
}
private function ioErrorHandler(event:IOErrorEvent):void {

}


Yes Robert, I tried with full and relative path too..but it doesnt work anyway.
Thanks
Naty
0 Kudos
NatashaManzuiga
Regular Contributor
Hi Robert,
Could u test this function with a pdf file?
Cheers,

Naty
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Naty,

     You can only use the loader object for certain types of images. It will not work for pdf files. If you had a trace statement in your error function you could see that it is error with an unknown file type error. If you Google how to verify that a file exists on the server you will see that this has to be done with server side code like PHP or ASP.
0 Kudos
DasaPaddock
Esri Regular Contributor
If you're only trying to test if you get an error or not, you could try using a URLLoader instead of a Loader.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Dasa,

   Thanks for the tip.


Naty,

   Based on Dasa's advice this works:

   public function IOErrorEventHandler(imgx:String):void {
    
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.BINARY;
    loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    loader.addEventListener(ProgressEvent.PROGRESS, onComplete); 
    var request:URLRequest = new URLRequest(imgx);
    loader.load(request);
   }
   private function onComplete (evt : Event) : void
   {
    var nameBuilding:String = Building1.selectedItem.@dgn;
    nameBuilding="CleanPrintA4/" + nameBuilding.toString().substr(0,nameBuilding.leng th-4) + ".pdf";
    var u:URLRequest = new URLRequest(nameBuilding);
    navigateToURL(u, "_blank");
   }
   private function ioErrorHandler(event:IOErrorEvent):void {
    trace(event.toString());
   }
0 Kudos
NatashaManzuiga
Regular Contributor
Dasa,

   Thanks for the tip.


Naty,

   Based on Dasa's advice this works:

   public function IOErrorEventHandler(imgx:String):void {
    
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.BINARY;
    loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    loader.addEventListener(ProgressEvent.PROGRESS, onComplete); 
    var request:URLRequest = new URLRequest(imgx);
    loader.load(request);
   }
   private function onComplete (evt : Event) : void
   {
    var nameBuilding:String = Building1.selectedItem.@dgn;
    nameBuilding="CleanPrintA4/" + nameBuilding.toString().substr(0,nameBuilding.leng th-4) + ".pdf";
    var u:URLRequest = new URLRequest(nameBuilding);
    navigateToURL(u, "_blank");
   }
   private function ioErrorHandler(event:IOErrorEvent):void {
    trace(event.toString());
   }


Many thanks Dasa and Robert...
I finally fixed it...
Robert is it possible to run this OnComplete function from the menu?
I wish I could launch PDF by the menu...based on "Building1.selectedItem.@dgn"

Cheers,

Naty
0 Kudos
NatashaManzuiga
Regular Contributor
Many thanks Dasa and Robert...
I finally fixed it...
Robert is it possible to run this OnComplete function from the menu?
I wish I could launch PDF by the menu...based on "Building1.selectedItem.@dgn"

Cheers,

Naty


Hi all, I almost solved my problem..
1) I added a "link" in config.xml
2) I modified the function "menuItemClick()" in the ControllerMenuItem.mxml and  by the "label" value I assigned at my link I can call all the URL I want by code...so I can bypass the URL in config.xml.
My problem is that I still cant get the value in my MiniSearch widget...
How can I get the value Robert?
Thanks,

Naty
0 Kudos