11package flixel .addons .plugin .screengrab ;
22
33#if !js
4+ import openfl .Lib ;
45import openfl .display .Bitmap ;
56import openfl .display .BitmapData ;
67import openfl .geom .Matrix ;
@@ -11,7 +12,7 @@ import flixel.FlxG;
1112import flixel .input .keyboard .FlxKey ;
1213#if sys
1314import lime .ui .FileDialog ;
14- import lime .ui .FileDialogType ;
15+ import lime .ui .FileDialogFilter ;
1516import openfl .display .PNGEncoderOptions ;
1617#else
1718import openfl .net .FileReference ;
@@ -175,41 +176,24 @@ class FlxScreenGrab extends FlxBasic
175176 file .save (png , Filename );
176177 #elseif (!lime_legacy || lime < "2.9.0")
177178 var documentsDirectory = " " ;
179+
178180 #if lime_legacy
179181 documentsDirectory = openfl.filesystem. File .documentsDirectory .nativePath ;
180182 #else
181183 documentsDirectory = lime.system. System .documentsDirectory ;
182184 #end
183185
184- var fd : FileDialog = new FileDialog ();
185-
186- var path = " " ;
187-
188- fd .onSelect .add (function (str : String )
189- {
190- path = fixFilename (str );
191- var f = sys.io. File .write (path , true );
192- f .writeString (png .readUTFBytes (png .length ));
193- f .close ();
194- path = null ;
195- });
196-
197- try
198- {
199- fd .browse (FileDialogType .SAVE , " *.png" , documentsDirectory );
200- }
201- catch (msg : String )
202- {
203- path = Filename ; // if there was an error write out to default directory (game install directory)
204- }
205-
206- if (path != " " && path != null ) // if path is empty, the user cancelled the save operation and we can safely do nothing
186+ FileDialog .saveFile (FlxG .stage .window , function (filepath : String , filter ): Void
207187 {
208- path = fixFilename (path );
209- var f = sys.io. File .write (path , true );
210- f .writeString (png .readUTFBytes (png .length ));
211- f .close ();
212- }
188+ if (filepath != null )
189+ {
190+ var path = fixFilename (filepath );
191+ var f = sys.io. File .write (path , true );
192+ f .writeString (png .readUTFBytes (png .length ));
193+ f .close ();
194+ path = null ;
195+ }
196+ }, [new FileDialogFilter (" PNG images" , " png" )], documentsDirectory );
213197 #end
214198 }
215199
0 commit comments