How to get file path after saving using FileReference - actionscript-3

With the following code I save recorded sound to local place that user select.
the thing I need is getting full path of the saved file.
function recordComplete(e:Event):void
{
fileReference.save(recorder.output, "recording.wav");
fileReference.addEventListener(Event.COMPLETE, fileSaved);
}
function fileSaved(e:Event)
{
trace("SAved");
}
Thanks a lot.

Related

How to make gulp work with files without extension

I want to make gulp work with files without extension also. I tried to do it the following ways:
function someTask() {
return gulp.src('./src/**/*.{html,,xml,txt}')
.pipe(gulp.dest('./build'));
}
function someTask() {
return gulp.src('./src/**/*.{html,!*,xml,txt}')
.pipe(gulp.dest('./build'));
}
function someTask() {
return gulp.src('./src/**/*.{html,[^*],xml,txt}')
.pipe(gulp.dest('./build'));
}
but I haven't got any results. Any suggestions?
I am still trying to find a better answer, but one route is to get all the files and then eliminate the extentions you don't want. Like
var debug = require('gulp-debug'); // nice, will list all the files in the stream
return gulp.src(['./src/**/*', '!./src/**/*.{js,png}'])
.pipe(debug())
.pipe(gulp.dest('./build'));
So here {js,png} list the possible file extensions in your src directories you don't want.
Hopefully there is a better answer.
[EDIT]: Maybe there is, try this:
return gulp.src(['./src/**/*.{html,xml,txt}', './src/**/!(*\.*)'])
This part ./src/**/!(*\.*) appears to match only files with no . in them, i.e., no extention.

Passing JSON Config into multiple instances of the same bundled React Application

I have several instances of a react-slick carousel. Each of them requires a different set of config options.
Currently, I have the carousel component bundled up via webpack and then deployed to multiple locations. Unfortunately, this means that the bundle is slightly different in each case, as the config file changes the overall bundle! What's the right approach for this solution?
I feel like I can think of the following solutions:
1) Load the config file asynchronously. Seems like a lazy solution, because making an extra round trip is overkill.
2) Try to use require.ensure to split out the config file into it's own chunk.
What's the right approach for this solution?
Thanks!
To reply for point 1, I've managed to accomplish runtime loading of config this way:
import xhr from 'xhr'
class Config {
load_external_config = (cb) => {
xhr.get("config.json", {
sync: true,
timeout: 3000
},(error, response, body)=>{
if(response.statusCode==200) {
try{
const conf = JSON.parse(body);
for(var i in conf) {
this[i] = conf[i];
}
}catch(e){
/* Manage error */
}
} else {
/* Manage error */
}
})
}
}
export let config = new Config();
The class above has two basic functions, on the one hand it is a "singleton", so every time you import it in each file of your project, the istance remain the same and will not be duplicated. On the other hand, through a XHR package it loads (synchronously) an external json file and puts every config voice in its instance as a first level attribute. Later, you will be able to do this:
import { config } from './config'
config.load_external_config();
config.MY_VAR
For point 2 I would like to see some examples, and I will remain tuned to this post for someone more skilled than me.

Phonegap file writer is not working, cannot truncate file content

I am using phonegap file reading functionality, once i read the content and i will do some functionality with that content, once that over i am calling file truncate functionality. In that i can't truncate any value. Help me to fix this issue.
removeFileContent();
function removeFileContent(){
console.log("Inside remove file content");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileTruncate, onProcessFailure);
};
function gotFileTruncate(fileSystem){
console.log("Inside get file path for remove content");
/** Function to get file path */
filePath = getFilePath(device.platform);
console.log("Device File Path to remove content-->"+this.filePath);
fileSystem.root.getFile(filePath, null, gotFileEntryTruncate, onProcessFailure);
}
function gotFileEntryTruncate(fileEntry){
globals.raiseLog("Inside file to truncate call");
globals.raiseLog("File Name-->"+fileEntry.name);
fileEntry.createWriter(gotFileWriter, onProcessFailure);
}
function gotFileWriter(writer){
globals.raiseLog("Inside file writer to truncate file content");
globals.raiseLog("Content length-->"+writer.length);
//writer.truncate(10);
writer.onwriteend = function(evt) {
writer.truncate(0);
writer.onwriteend = function(evt) {
};
};
writer.write("");
globals.raiseLog("Content length after truncate-->"+writer.length);
}
In the above gotFileWriter() if i check for writer.length its still showing some count. I dont know how come we can check the file gets empty. I having some text inside that file. Need to clear the file when i finish the reading of the file. I am calling removeFileContent() after i finish the reading functionality. Kindly help.
The way your code is written you may get a false positive that the file still has contents in it. Move your:
globals.raiseLog("Content length after truncate-->"+writer.length);
into your onwriteend function as the write call is async and may not finish before your log is printed.

Flash Builder will not read local JSON file . .

So I've tried to build a small utility to view the contents of a JSON file in an easy-to-understand manner (for non-tech people).
I have Googled far and wide, high and low, but every example that shows how to consume a JSON file in Flash Builder uses the HTTP service, pointing to a file on the web.
Here I am, sitting in front of my MacBook, wondering why I can't make this work. In the documentation I've found (sort of relating to this issue), they always show Windows examples, and they seem to work fine:
C://me/projects/json/my_json.json
Perhaps I'm completely missing the obvious, but is this possible on a Mac as well?
I've tried
file:///Users/me/projects/json/my_json.json
That doesn't work. I've tried some "resolve to path" syntax, but the HTTP service does not seem to allow for anything but file paths in quotes.
Would anyone be able to pint me in the right direction?
Use the File API. It's really easy, here's a quick code sample:
// Get a File reference, starting on the desktop.
// If you have a specific file you want to open you could do this:
// var file:File = File.desktopDirectory.resolvePath("myfile.json")
// Then skip directly to readFile()
var file:File = File.desktopDirectory;
// Add a listener for when the user selects a file
file.addEventListener(Event.SELECT, onSelect);
// Add a listener for when the user cancels selecting a file
file.addEventListener(Event.CANCEL, onCancel);
// This will restrict the file open dialog such that you
// can only open .json files
var filter:FileFilter = new FileFilter("JSON Files", "*.json");
// Open the file browse dialog
file.browseForOpen("Open a file", [filter]);
// Select event handler
private function onSelect(e:Event):void
{
// Remove listeners on e.currentTarget
// ...
// Cast to File
var selectedFile:File = e.currentTarget as File;
readFile(selectedFile);
}
private function onCancel(e:Event):void
{
// Remove listeners on e.currentTarget
// ...
}
private function readFile(file:File):void
{
// Read file
var fs:FileStream = new FileStream();
fs.open(selectedFile, FileMode.READ);
var contents:String = fs.readUTFBytes(selectedFile.size);
fs.close()
// Parse your JSON for display or whatever you need it for
parseJSON(contents);
}
You hinted at this in your post about examples being for Windows and you being on a Mac but I'll state it explicitly here: you should always use the File API because it is cross platform. This code will work equally well on Windows and Mac.

Updating a flickr image upon user input

I am trying to integrate flickr into a weather app (yahoo weather api) that I've created and decided to start by leveraging flickrGrabber (http://blog.organa.ca/?p=19) as a starting point. I have both the weather app and flickrGrabber working however updating flickrGrabber after initial load is proving very challenging for me.
The initial image is being pulled via a search term set by a variable called flickrLocationName and I am able to update the variable value successfully upon entry of a new zip code however I can't seem to get flickrGrabber to unload & reload with the new value. My flickrGrabber code is on layer documentAS. The flickrGrabber class can be found within the Src folder and var flickrLocationName gets set from the WeatherObject class which can also found in the Src folder.
You can see what I mean by visiting this link:
http://truimage.biz/WAS400/WeatherApp/Deploy/weatherApp.html
Of course my source can be downloaded here:
http://truimage.biz/WAS400/weatherApp.zip
Any help would be very much appreciated. Here is some sample code:
import flickrGrabber;
var apiKey:String = "####"; //The working API key is in the zip file
var apiSecret:String = "####"; //The working API secret is in the zip file
var flickrLocationName:String;
var grabber:flickrGrabber;
function locationImage():void
{
grabber = new flickrGrabber(1024,600,apiKey,apiSecret,flickrLocationName,false);
grabber.addEventListener("imageReady", onLoadedImage);
grabber.addEventListener("flickrGrabberError", onErrorImage);
grabber.addEventListener("flickrConnectionReady", onFlickrReady);
function onFlickrReady(evt:Event):void
{
grabber.loadNextImage();
}
function onLoadedImage(evt:Event):void
{
addChildAt(grabber.image,0);
}
function onErrorImage(evt:ErrorEvent):void
{
trace("Report error: " + evt.text);
}
}
I'm pretty sure to change the image I need to remove the
addChildAt(grabber.image,0);
and rerun the function
locationImage();
But his is my best guess.