0

In my recent project, I need to get a file path where the user can specify/choose the file by using Dialog Box.

This is my code in order to do just that;

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.Event;

    import flash.filesystem.File;
    import flash.net.FileFilter;

    import xlsxreader.Worksheet;
    import xlsxreader.XLSXLoader;

    public class MainClass extends MovieClip
    {
        var fileGet: File = new File();
        var excel_loader: XLSXLoader = new XLSXLoader();

        public function STRIMSMainClass()
        {
            var import_btn: MovieClip = MovieClip(root).powerButton_mc.utilitiesButton_mc;

            import_btn.addEventListener(MouseEvent.CLICK, selectExcelFile);

            fileGet = File.applicationDirectory;
            fileGet.addEventListener(Event.CANCEL, fileCancel);
            fileGet.addEventListener(Event.SELECT, fileSelect);

            excel_loader.addEventListener(Event.COMPLETE, loadingComplete);
        }

        function selectExcelFile(e: MouseEvent): void
        {
            var fileFilter = new FileFilter("Select Excel File", "*.xls;*.xlsx;*.xlsm");

            fileGet.browseForOpen("Select Excel File", [fileFilter]);
        }

        function fileCancel(e: Event): void
        {}

        function fileSelect(e: Event): void
        {
            excel_loader.load(fileGet.nativePath);
        }

        function loadingComplete(e: Event): void
        {}
    }
}

However, the published .exe file can not be open by my computer; it just flash and automatically close itself. I test the code before publish and it work just fine.

When I try to go through the code line by line, by delete this line var fileGet: File = new File() and obviously any line that associate with it, the .exe file can be open just fine.

I need filesystem.File for to get the .nativePath of the file that need to be open, so I can not exclude var fileGet: File = new File(). This also happen in my colleague's PC.

Please help me solve this weird error that happen right now. This is my first time trying to use Adobe Animate to develop software.

Fahmieyz
  • 255
  • 4
  • 19
  • The probable reason is that you publish EXE projector, which doesn't support AIR classes. You should use the compatible **FileReference** class instead. – Organis Nov 05 '19 at 20:26
  • @Organis but I already use 'Air for Dekstop' in settings.. is that still a no? – Fahmieyz Nov 06 '19 at 06:24
  • @Organis and if i remember correctly, FileReference cant return file path like filesystem.File... or is there actually a way to use it with FileReference? – Fahmieyz Nov 06 '19 at 06:26
  • When you publish 'AIR for Desktop' target you get either AIR installable package or self-sufficient EXE installer, but not a standalone projector. When you publish standalone projector, it is compatible with browser-limited Flash Player, not AIR. Anyway. If you need to load a file, you can totally do it with **FileReference.load(...)** method, you just don't get to know the URL: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#load() – Organis Nov 06 '19 at 07:02
  • @Organis thats the thing... i need to know the .exe native path and use it as default location. As far as i know you cant get native file path from FileReference, which i need to use the default location as a way to stored my data. – Fahmieyz Nov 06 '19 at 08:57
  • Well, then you need to actually publish it as AIR application. – Organis Nov 06 '19 at 09:08
  • @Organis doesnt by making 'AIR 30.0 for Desktop' in publish setting already make it as AIR applicarion? – Fahmieyz Nov 08 '19 at 11:49
  • No. You need to actually **publish** it as AIR installer (which produces .air package or self-sufficient .exe installer) then install this AIR application to your PC. – Organis Nov 09 '19 at 18:23
  • @Fahmieyz When making the AIR did you see an option to provide app's icon? Can you see your app in the control panel (under Installed Programs)?. If not, maybe you're having [a similar problem to this one](https://stackoverflow.com/questions/43061515/adobe-flash-cs6-output-window-closes-automatically-while-executing-filesteam-ope/43079318#comment73297708_43079318)? Read the comments there and see if that [linked solution](https://www.dummies.com/software/adobe/flash/how-to-publish-an-air-application-in-adobe-flash-cs6/) helps you. Ask anything if not sure about certificates, app icons etc. – VC.One Nov 09 '19 at 22:00

0 Answers0