Home | Stories | Reviews | Treo™ Store | Accessories | Software | Discussion | Mobile | About | Search

 
 
Treo Screen Protectors  (3-Pack) Screen Protectors for Treo
Just $12.95
Cruiser Bluetooth Car Kit Speakerphone Jabra Cruiser Bluetooth Car Kit Speakerphone
Just $89.95
Innocell 1750mAh Extended Battery Seidio Innocell 1750mAh Extended Battery for Treo Pro
Just $49.95
BackBeat 903 Stereo Bluetooth Headset Plantronics BackBeat 903 Stereo Bluetooth Headset
Just $89.95
 
Old 10/18/2009, 05:22 AM   #1 (permalink)
Member
 
Join Date: Aug 2009
Posts: 31
Thanks: 2
Thanked 1 Time in 1 Post
Default How to test if a file exists ?

Hi all,

In my app, i parse a parameter from Scene1 to Scene2.

This parameter is correctly declared In Scene2.
Here is the code of Scene2:
Code:
function Scene2Assistant(param) {
this.param1 = param;
}
This parameter is used to display a picture in Scene2 when Scene2 is activated

Here is the code :
Code:
Scene2Assistant.prototype.activate = function(event) {
	this.myCountryDivElement.mojo.manualSize('320','350');
	this.myCountryDivElement.mojo.centerUrlProvided('images/'+ this.param1 +'.jpg');
}
All works fine when an image file corresponding to the parameter exists.


what i want to do is to check if the file corresponding to the parameter parsed exists.
If Yes, then the value of this.param1 is take into account
If No, then i want to set a default value.

Is this test must be coded in protoype.setup as below ?
Code:
Scene2Assistant.prototype.setup = function() {
	var file = Mojo.appPath + 'images/' + this.param1+'.jpg'
             ...................
             ..................


I browse the forum but not find something relevant.
What is the code to do it ?

Thanks for your help.
Ze-Palm is offline   Reply With Quote
Old 10/18/2009, 11:52 PM   #2 (permalink)
Member
 
Join Date: Aug 2009
Posts: 31
Thanks: 2
Thanked 1 Time in 1 Post
Question

Up ! Anyone ?
Ze-Palm is offline   Reply With Quote
Old 10/20/2009, 01:58 PM   #3 (permalink)
Member
 
Join Date: Aug 2009
Posts: 31
Thanks: 2
Thanked 1 Time in 1 Post
Question

I tried a lot of syntaxes, read guidelines, ... but not fixed my problem.

In this large and friendly community, is there a guru to help me ?

Any help would be really appreciated.
Ze-Palm is offline   Reply With Quote
Old 10/20/2009, 06:28 PM   #4 (permalink)
Pre Developer
 
PreGame's Avatar
 
Join Date: Jun 2009
Posts: 499
Thanks: 22
Thanked 748 Times in 66 Posts
Default

you would have to use one of palm's API's to do that. You can TRY to do an Ajax.Request('/path/to/file',...); to see if it returns data. But other than that javascript cannot really open files without the use of activex.
__________________
Donations are greatly appreciated and can be donated
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
. Again thank you ALL for your continued support!
PreGame is offline   Reply With Quote
Thanked By:
Old 10/22/2009, 01:35 AM   #5 (permalink)
Member
 
Join Date: Aug 2009
Posts: 31
Thanks: 2
Thanked 1 Time in 1 Post
Default

Thanks PreGame.
Ajax.Request function seems to be the solution

First of all, i try to display the path but am having trouble to figure out.
Code:
var url = Mojo.appPath + 'images/' + this.param1;
this.showDialogBox('Path', url);

In which section of the scene the test must be coded ?
I tried in prototype.setup and prototype.activate but it don't work.

Any help ?
Ze-Palm is offline   Reply With Quote
Old 11/05/2009, 09:50 AM   #6 (permalink)
Member
 
Join Date: Aug 2009
Posts: 31
Thanks: 2
Thanked 1 Time in 1 Post
Default

Ajax.Request is the solution. Thanks PreGame

Here is the code for whom who are interested in:

Considering that :
this.param1 is an argument parsed from Scene1
This code is to test if a jpg file exists in the app path.

Code:
var file = Mojo.appPath + this.param1 +'.jpg';
	var request = new Ajax.Request(file, {
        	method: "get",
        	onSuccess: this.OnSuccess.bind(this),
        	onFailure: this.OnFailure.bind(this)
    	});

If the file exists then the correct jpg is displayed
Code:
Scene2Assistant.prototype.OnSuccess = function(transport){
	this.myCountryDivElement.mojo.centerUrlProvided(this.param1 +'.jpg');
};

If the file not exists then a default jpg is displayed
Code:
Scene2Assistant.prototype.OnFailure = function(transport){
	this.myCountryDivElement.mojo.centerUrlProvided('Map-Demo.jpg');
};
Hope this helps
Ze-Palm is offline   Reply With Quote
Reply


Thread Tools
Display Modes

~


All times are GMT -4. The time now is 06:17 PM.

Creating smartphone communities
Android Central - Android reviews, news and forums Crackberry - Blackberry news, reviews and community TiPb - iPhone news, accessory reviews & forums
Pre Central - Palm Pre Review, News and Community Treo Central - Treo & Centro News and Forums WMExperts - Windows Mobile Reviews & News

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
 
 

Copyright ©1999- TreoCentral. All rights reserved : Terms of Use : Privacy Policy

TREO and TreoCentral are trademarks or registered trademarks of palm, Inc. in the United States and other countries;
the TreoCentral mark and domain name are used under license from palm, Inc.
The views expressed on this website are solely those of the proprietor, or
contributors to the site, and do not necessarily reflect the views of palm, Inc.

Explore More: Crackberry | WMExperts | the iPhone Blog | Android Central | Smartphone Experts Combined Forums