Hello guys,
i create simple function where from selected files via input file element, by using FileReader I create simple image element. Its working fine but inside of this function during using class FileReader which contains Constraints Function (onloadstart, onprogress, onload, onabort, onerror, onloadend - i am not sure but I called them as Constraints Function) I cant find solution in Haxe how to do for example this steps: if onloadstart is finished, then onload and then onloadend. I know that there are Promises like one solution (i am not sure if there is more practically solutions) but I dont know how to do it in Haxe.
If you have any solutions i am using the newest version of Haxe and also I can try it on 3.4.7
This is my function but as i mentioned above Constraints are wrong inside of function,
Thanks you a lot of
private function createImageFromFileViaFileReader( file:File ):ImageElement
{
var img:ImageElement = cast document.createElement("img");
var fileReader = new FileReader();
// TO DO
fileReader.onloadstart = function(e) {
trace('loading...');
if(window.confirm()) {
fileReader.onload = function(e) {
img.src = e.target.result;
img.height = 60;
trace('loading...');
}
fileReader.onloadend = function(e) {
trace('finished');
}
return true;
} else {
return false;
}
}
fileReader.readAsDataURL(file);
return img;
}