Referencia loadStrings()

loadStrings()

Loads a text file to create an Array.

The first parameter, path, is always a string with the path to the file. Paths to local files should be relative, as in loadStrings('/assets/data.txt'). URLs such as 'https://example.com/data.txt' may be blocked due to browser security.

The second parameter, successCallback, is optional. If a function is passed, as in loadStrings('/assets/data.txt', handleData), then the handleData() function will be called once the data loads. The array created from the text data will be passed to handleData() as its only argument.

The third parameter, failureCallback, is also optional. If a function is passed, as in loadStrings('/assets/data.txt', handleData, handleFailure), then the handleFailure() function will be called if an error occurs while loading. The Error object will be passed to handleFailure() as its only argument.

Note: Data can take time to load. Calling loadStrings() within preload() ensures data loads before it's used in setup() or draw().

Ejemplos

Sintaxis

loadStrings(path, [successCallback], [errorCallback])

Parámetros

path

path of the text file to be loaded.

successCallback

function to call once the data is loaded. Will be passed the array.

errorCallback

function to call if the data fails to load. Will be passed an Error event object.

Notice any errors or typos? Please let us know. Please feel free to edit src/io/files.js and open a pull request!

Referencias Relacionadas