Where to put loadBytes()?

Hi

Can anyone confirm … can loadBytes() only be used in preload() ?
If I try in setup() or anywhere else (e.g. in a new class) it doesn’t work.


let data;

function preload() {
  data = loadBytes('assets/kick.wav');
}

function setup() {
//putting loadBytes() here doesn't seem to work?
//data = loadBytes('assets/kick.wav');

  for (let i = 0; i < 5; i++) {
    console.log("bytes[" + i + "] = " + data.bytes[i]) ;
  }
}

function draw() {

}
1 Like

wrong timing: need to wait…
https://editor.p5js.org/kll/sketches/X0KSkVzeg
works

1 Like

@kll
Many thanks again … will use the callbacks!

1 Like