out of the blue I get this strange error when I try to show a file dialog. No code changes on my side and it was still running fine when I last complied (neko64) 5 days ago.
I’m on OSX 10.12. openfl 4.9.2/lime 4.0.3 - ((5.0.0)/4.1.0 produce the same result.)
Any ideas? I’m really at a loss as to what is happening.
package;
import lime.ui.FileDialog;
import openfl.display.Sprite;
class Main extends Sprite {
public function new () {
super ();
var sprite = new Sprite ();
sprite.graphics.beginFill (0xFF0000);
sprite.graphics.drawRect (0, 0, 100, 100);
addChild (sprite);
addEventListener ("enterFrame", function (_) sprite.x += 0.5);
var dialog = new FileDialog ();
dialog.onSelect.add (function (path) trace (path));
dialog.browse ();
}
}
Are you using FileDialog, or FileReference?
OpenFL FileReference uses Lime FileDialog internally. If FileDialog works but FileReference does not, let me know what your code looks like and I can look into it
Hmm, this worked for me… I’m on Linux right now, though:
package;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.net.FileFilter;
import openfl.net.FileReference;
class Main extends Sprite {
private var file:FileReference;
public function new () {
super ();
showDialog ();
}
private function showDialog():Void{
trace("showDialog");
file = new FileReference();
var textFileTypes:FileFilter = new FileFilter("Text (*.txt)", "*.xml");
file.browse([textFileTypes]);
file.addEventListener(Event.SELECT, selectFile);
}
private function selectFile(e:Event):Void
{
trace("file selected"+file);
file.addEventListener(Event.COMPLETE, loadFile);
file.load();
}
private function loadFile(e:Event):Void{
var storyXML = Std.string(file.data);
trace (storyXML);
//processStory(storyXML);
}
}
Oh, try and listen to Event.SELECT before you call file.browse, it might be occurring synchronously on your system
Hm. Ok this is what I see now. Essentially the COMPLETE event after loading does not seem to fire, even though all data is there in the trace after the load command
private function showDialog():Void{
trace("showDialog");
file=new FileReference();
var textFileTypes:FileFilter = new FileFilter("Text (*.txt)", "*.xml");
file.addEventListener(Event.SELECT, selectFile);
file.browse([textFileTypes]);
}
//above works
private function selectFile(e:Event):Void
{
trace("file selected"+file.name+" data"+file.data); //file.data = null
file.addEventListener(Event.COMPLETE, loadFile);
file.load();
trace("file selected"+file.name+" data"+file.data); //file.data is there, so loading does work.
}