All the walkthroughs I've seen specify either desktop, local files as the initial view when calling browseForOpen.
Is there a way to have the air application remember the last location a file was loaded from and default back there?
If necessary I suppose the path could be written to the local db, but even still, I do not know how to get the filepath of the loaded file.
You can use File.nativePath and File.resolvePath.
A few years later, perhaps, but thought this might help someone in the future.
var file:File = new File();
file.browseForOpen("Open");
This will open the last location.
Related
What is the correct way to display a HTML file downloaded and saved in the file system? I am able to download and save the html page in the .cn1 folder on Simulator but it doesn't display. I tested using the Page.html sample file found in the old Kitchen Sink demo.
Also, how can I use hardcoded paths like file:///storage/emulated/0/Folder/Page.html instead? I have tried but nothing appears in common folders in the phone e.g. the Android folder. Below is what I have done so far!
`Form fm_brw = new Form();`
`fm_brw.setLayout(new BorderLayout());`
`FileSystemStorage fs = FileSystemStorage.getInstance();`
`fs.mkdir(fs.getAppHomePath() + "SampleFolder");`
`Util.downloadUrlToFile("http://somesite.com/Page.html", fs.getAppHomePath() + "SampleFolder/Page.html", true);`
`BrowserComponent browser = new BrowserComponent();`
`browser.setURL(fs.getAppHomePath() + "SampleFolder/Page.html);`
`fm_brw.addComponent(BorderLayout.CENTER, browser);`
`fm_brw.show();`
You can't hardcode paths on phones as those differ even on the same phone for new installs to keep app isolation.
Your approach is correct but I'm assuming the html refers to images and other resources which are now unavailable so the process of downloading an HTML file for offline viewing is more complex as you would need to download all the resources then edit the HTML source to reference local files instead of server files.
#Shai Almog - Happy 2018 and please accept my apologies for the delayed reply. I figured out the reason for the webpage not diplaying... apparently, you have to add the "file://" when setting the url i.e. browser.setURL("file://"+str_homePath+str_filePath);
If this is not by your design then I can file an RFE.
I'm working on a windows universal app. I want to show the user an image. The image is located in a subfolder within my assets folder, in both the phone and the windows folder.
I'm trying to put the image in a variable in a class that is in the shared folder. I am continously getting uri exceptions.
My code looks like this:
Uri uri = new Uri("/Assets/Image/avatar_anonymous.png");
chat_profilepicture_Bitmap = new BitmapImage(uri);
I've tried different urls, with and without capitals, the entire path "C://blablabla", and many more. Nothing seems to be working. I have also tried: pack://application:,,,/ which was suggested by multiple stackoverflow threads. But no luck there.
I'm thinking the problem lies in the image being in another project, is there a way to get around this? Or if this isn't the problem, what am I doing wrong?
Try this
Uri uri = new Uri("ms-appx:///Assets/Image/avatar_anonymous.png");
Hope this helps
In Windows Universal App, You can use Image Resource with ms-appx or ms-appdata.
ms-appx means using resource in App Package
ms-appdata menas using resource in floder of local, temp or roam.
So the uri can be written like this:
new Uri("ms-appx:///Assets/Image/avatar_anonymous.png", UriKind.Absolute);
or
new Uri("ms-appdata:///LocalFolderName/demo.png", UriKind.Absolute);
I feel as if I'm missing something very basic here. I'm trying to add an option to let export images from an Android app in PNG format. The code seems to work fine on my Droid Bionic and doesn't error out, but afterwards I can't find the image anywhere in the phone's storage. Where is it going? Is it possible to access images exported from an AIR app? Am I missing something completely obvious?
bdToSave.draw(screenshot);
var arrBytes:ByteArray = PNGEncoder.encode(bdToSave);
var file:File = File.desktopDirectory.resolvePath("testimage.png");
var fileStream:FileStream = new FileStream();
try {
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(arrBytes);
fileStream.close();
}
catch (errObject:Error) {
Env.outBox.text = "Error writing image file!"
}
I've also used the CameraRoll class to successfully export images and found the resulting files easily, but the images there seemed to use bad JPEG compression. So I was hoping using FileStream instead would result in nicer images.
File.desktopDirectory does not exist on Android. Use File.applicationDirectory or File.applicationStorageDirectory to write to the internal disk. You almost always want to use applicationStorageDirectory and I believe that is actually the only one you can use on iOS for writing data. For writing to external drives, and this is untested on my part, I believe you want to use File.documentsDirectory. Trace out File.documentsDirectory.nativePath to verify that is the correct path.
It might be wise to consider that the majority of higher-end phones being released now do not contain SD cards. If this is meant to be a mass market product, I'd recommend using applicationStorageDirectory instead.
I am using AS3 to make a game. I use RequestURL( filename ) to obtain the music I want to play. However, this means the music file has to be in the same folder as the .fla file. How can I use it to get a music file from a different folder? I don't really like having to leave my music outside of a Music folder or properly organised somehow....
EDIT: Should have mentioned this earlier. I tried to use simply something such as "whatever/filename", but I got this security error:
SecurityError: Error #2000: No active security context.
Why?
Have you tried using the flash.media.Sound.load() method yet?
//Make a new sound object
var s:Sound = new Sound();
//Load it
s.load(new URLRequest("someDifferentMusicFolder/loop.mp3"));
//Play it
s.play()
If you are loading it via another method, such as URLLoader + URLRequest, please post your code and we should be able to help a little better.
Generally speaking though URLRequests should allow you to specify different folders, so your problem may not be in the methodology you are using but may be in your implementation? Perhaps you are getting a security error? Whatever it may be, if you post your code we can help you narrow it down.
I want to create a stand alone pure flash application with external xml loading from the same dir. In that i want to update/overwirite my xml nodes and save it internally at run time (I dont want to go for fileReference class to save/overWrite my xml). when I load my apps next time it will react based on the updated xml.
I dont want go for AIR as it requires installation at end user side.
I cant use any server side script.
Is it possible in flash AS3.0?
Please suggest any possible solution.
Thanks..
it's possible with FileReference.save()
here is an example saving .txt files
var file:File = File.userDirectory.resolvePath("test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTFBytes("text to save");
fileStream.close();
last time I tried this worked without any prompt as to where to save . . . if it helps anyone.
(above worked with mobile devices saving to SDcard) - you will need to allow (WRITE_EXTERNAL_STORAGE) permission.
You can't access files in Flash without AIR and FileReference, but you can save data in SharedObject. This is analogous to cookies in browser (but not tied to one). Data will be saved somewhere in "C:\Users\UserName\Application Data\Macromedia\Flash Player\" directory (example for Win7) until user clears it or available disk size is exceeded.