4 Replies Latest reply on Aug 31, 2012 2:27 PM by fewremain

    Desktop AIR Application installs fine on Mac... crashes on PC

    fewremain

      Hey guys,

       

      I ran into an issue that has be pulling my hair out. I have a very simple AIR application that was built with Flash CS6 on a Mac. The published app installs and runs perfectly on my Mac. Installation goes just fine on a PC, but the app will not launch! The window starts to come up and immediately crashes. I just finished making a desktop app in the last version of AIR and it ran perfect on PC.

       

      Has anyone else experienced this issue? So much fun using a Mac when most clients use PC lol!

        • 1. Re: Desktop AIR Application installs fine on Mac... crashes on PC
          adobe_paul Adobe Employee

          It's hard to say what the problem is without seeing the code. The best advice I can offer is to look for things that might be platform specific, such as hard-coded file paths and Mac-specific apis (like the dock icon/menu).

           

          Paul Robertson

          Adobe Developer Relations

          • 2. Re: Desktop AIR Application installs fine on Mac... crashes on PC
            fewremain Level 1

            It's actually quite a tiny app. Tiny enough that I'm just coding in Flash CS6 in the first frame noob style LOL. I published another AIR app like this recently and it worked just fine on PC.

             

            Here is literally all of the code that runs the app. I am using the File class to access the desktop directory for some files, but my understanding is that it should access the desktop the same on PC and Mac.

             

            Thanks for the time and help... I could have a friend publish on a PC, but it would be much more convenient if I could get it to work correctly .

             

            import flash.display.MovieClip;

            import flash.display.SimpleButton;

            import flash.events.MouseEvent;

            import flash.filesystem.File;

            import flash.display.Loader;

            import flash.ui.MouseCursor;

             

             

             

            /////////////////////////////////////////////////

            // START VARIABLE DECLARATION

            /////////////////////////////////////////////////

             

            var XMLDirectory:File = File.desktopDirectory;

            XMLDirectory = XMLDirectory.resolvePath("missing_person/results.xml");

            var myXML:XML;

             

            var imageDirectory:File = File.desktopDirectory;

            imageDirectory = imageDirectory.resolvePath("missing_person/images/");

             

            var screen_saver:MovieClip;

            var part1_mc:MovieClip;

            var part2_mc:MovieClip;

            var rightBtn:SimpleButton = part2_mc.right_btn;

            var leftBtn:SimpleButton = part2_mc.left_btn;

            var heightOpt:MovieClip = part1_mc.height_options_mc;

            var heightBtn:SimpleButton = part1_mc.height_btn;

            var genderOpt:MovieClip = part1_mc.gender_options_mc;

            var genderBtn:SimpleButton = part1_mc.gender_btn;

            var ageOpt:MovieClip = part1_mc.age_options_mc;

            var ageBtn:SimpleButton = part1_mc.age_btn;

            var searchBtn:SimpleButton = part1_mc.search_btn;

            var resetBtn:SimpleButton = header_mc.restart_btn;

            var searchingDB:MovieClip = part1_mc.searching_mc;

             

            var startArray:Array = [[],[]];

             

            var ageStr:String = "";

            var heightStr:String = "";

            var genderStr:String = "";

             

            // KEEPS OVER STATES FOR BUTTONS

            var heightState = heightBtn.upState;

            var genderState = genderBtn.upState;

            var ageState = ageBtn.upState;

            var searchState = searchBtn.upState;

             

            // LOAD AND PARSE XML

            var myLoader:URLLoader = new URLLoader();

            myLoader.load(new URLRequest(XMLDirectory.url));

            myLoader.addEventListener(Event.COMPLETE, processXML);

             

            function processXML(e:Event):void

            {

                myXML = new XML(e.target.data);

             

                for (var i:int = 0; i < myXML.result.length(); i++)

                {

                    startArray[i] = [(imageDirectory.url + "/" + myXML.result[i].image), myXML.result[i].name, myXML.result[i].age, myXML.result[i].gender, myXML.result[i].height, myXML.result[i].description, myXML.result[i].features];

                    trace(startArray[i][0]);

                }

            }

             

             

            //CODE FOR BUTTON RESET

            resetBtn.addEventListener(MouseEvent.MOUSE_DOWN, resetAll);

             

            function resetAll(event:MouseEvent):void

            {

                enableButtons();

                heightOpt.visible = false;

                genderOpt.visible = false;

                ageOpt.visible = false;

                searchingDB.visible = false;

                part1_mc.height_txt.text = "";

                part1_mc.gender_txt.text = "";

                part1_mc.age_txt.text = "";

                part2_mc.visible = false;

                part2_mc.removeChild(resultContainer);

            }

             

             

            //BEGIN INITIALIZATION ;

             

             

            function init():void

            {

                    part1_mc.height_txt.text = "";

                part1_mc.gender_txt.text = "";

                part1_mc.age_txt.text = "";

                part1_mc.visible = false;

                part2_mc.visible = false;

                screen_saver.visible = true;

                heightOpt.visible = false;

                genderOpt.visible = false;

                ageOpt.visible = false;

                searchingDB.visible = false;

            }

             

            init();

             

             

            heightBtn.addEventListener(MouseEvent.MOUSE_DOWN, showHeights);

            genderBtn.addEventListener(MouseEvent.MOUSE_DOWN, showGenders);

            ageBtn.addEventListener(MouseEvent.MOUSE_DOWN, showAges);

             

             

            function showHeights(event:MouseEvent):void

            {

                heightOpt.visible = true;

                disableButtons();

                //ADD EVENT LISTENERS FOR HEIGHT OPTIONS

             

                heightOpt.opt_1.addEventListener(MouseEvent.MOUSE_DOWN, setHeight1);

                heightOpt.opt_2.addEventListener(MouseEvent.MOUSE_DOWN, setHeight2);

                heightOpt.opt_3.addEventListener(MouseEvent.MOUSE_DOWN, setHeight3);

                heightOpt.opt_4.addEventListener(MouseEvent.MOUSE_DOWN, setHeight4);

                heightOpt.opt_5.addEventListener(MouseEvent.MOUSE_DOWN, setHeight5);

                heightOpt.opt_6.addEventListener(MouseEvent.MOUSE_DOWN, setHeight6);

            }

             

            function showGenders(event:MouseEvent):void

            {

                genderOpt.visible = true;

                disableButtons();

                //ADD EVENT LISTENERS FOR HEIGHT OPTIONS

             

                genderOpt.opt_1.addEventListener(MouseEvent.MOUSE_DOWN, setGender1);

                genderOpt.opt_2.addEventListener(MouseEvent.MOUSE_DOWN, setGender2);

                genderOpt.opt_3.addEventListener(MouseEvent.MOUSE_DOWN, setGender3);

            }

             

            function showAges(event:MouseEvent):void

            {

                ageOpt.visible = true;

                disableButtons();

                //ADD EVENT LISTENERS FOR HEIGHT OPTIONS

             

                ageOpt.opt_1.addEventListener(MouseEvent.MOUSE_DOWN, setAge1);

                ageOpt.opt_2.addEventListener(MouseEvent.MOUSE_DOWN, setAge2);

                ageOpt.opt_3.addEventListener(MouseEvent.MOUSE_DOWN, setAge3);

                ageOpt.opt_4.addEventListener(MouseEvent.MOUSE_DOWN, setAge4);

                ageOpt.opt_5.addEventListener(MouseEvent.MOUSE_DOWN, setAge5);

                ageOpt.opt_6.addEventListener(MouseEvent.MOUSE_DOWN, setAge6);

            }

             

            function disableButtons():void

            {

                heightBtn.upState = heightBtn.downState;

                heightBtn.enabled = false;

             

                genderBtn.upState = genderBtn.downState;

                genderBtn.enabled = false;

             

                ageBtn.upState = ageBtn.downState;

                ageBtn.enabled = false;

             

                searchBtn.upState = searchBtn.downState;

                searchBtn.enabled = false;

            }

             

            function enableButtons():void

            {

                heightBtn.upState = heightState;

                heightBtn.overState = heightState;

                heightBtn.hitTestState = heightState;

                heightBtn.enabled = true;

             

                genderBtn.upState = genderState;

                genderBtn.overState = genderState;

                genderBtn.hitTestState = genderState;

                genderBtn.enabled = true;

             

                ageBtn.upState = ageState;

                ageBtn.overState = ageState;

                ageBtn.hitTestState = ageState;

                ageBtn.enabled = true;

             

                searchBtn.upState = searchState;

                searchBtn.overState = searchState;

                searchBtn.hitTestState = searchState;

                searchBtn.enabled = true;

            }

             

            //ASSORTED FUNCTIONS TO SET THE TEXT FOR THE HEIGHT OPTION

             

            function setHeight1(event:MouseEvent)

            {

                part1_mc.height_txt.text = "135-145cm";

                enableButtons();

                heightOpt.visible = false;

            }

             

            function setHeight2(event:MouseEvent)

            {

                part1_mc.height_txt.text = "145-155cm";

                enableButtons();

                heightOpt.visible = false;

            }

             

            function setHeight3(event:MouseEvent)

            {

                part1_mc.height_txt.text = "155-165cm";

                enableButtons();

                heightOpt.visible = false;

            }

             

            function setHeight4(event:MouseEvent)

            {

                part1_mc.height_txt.text = "165-175cm";

                enableButtons();

                heightOpt.visible = false;

            }

             

            function setHeight5(event:MouseEvent)

            {

                part1_mc.height_txt.text = "175-185cm";

                enableButtons();

                heightOpt.visible = false;

            }

             

            function setHeight6(event:MouseEvent)

            {

                part1_mc.height_txt.text = "Unknown";

                enableButtons();

                heightOpt.visible = false;

            }

             

             

            function setGender1(event:MouseEvent)

            {

                part1_mc.gender_txt.text = "Male";

                enableButtons();

                genderOpt.visible = false;

            }

             

            function setGender2(event:MouseEvent)

            {

                part1_mc.gender_txt.text = "Female";

                enableButtons();

                genderOpt.visible = false;

            }

             

            function setGender3(event:MouseEvent)

            {

                part1_mc.gender_txt.text = "Unknown";

                enableButtons();

                genderOpt.visible = false;

            }

             

            function setAge1(event:MouseEvent)

            {

                part1_mc.age_txt.text = "20-30 years old";

                enableButtons();

                ageOpt.visible = false;

            }

             

            function setAge2(event:MouseEvent)

            {

                part1_mc.age_txt.text = "31-40 years old";

                enableButtons();

                ageOpt.visible = false;

            }

             

            function setAge3(event:MouseEvent)

            {

                part1_mc.age_txt.text = "41-50 years old";

                enableButtons();

                ageOpt.visible = false;

            }

             

            function setAge4(event:MouseEvent)

            {

                part1_mc.age_txt.text = "51-60 years old";

                enableButtons();

                ageOpt.visible = false;

            }

             

            function setAge5(event:MouseEvent)

            {

                part1_mc.age_txt.text = "71-80 years old";

                enableButtons();

                ageOpt.visible = false;

            }

             

            function setAge6(event:MouseEvent)

            {

                part1_mc.age_txt.text = "Unknown";

                enableButtons();

                ageOpt.visible = false;

            }

             

            screen_saver.addEventListener(MouseEvent.CLICK, hideScreenSaver);

             

            function hideScreenSaver(event:MouseEvent):void

            {

                screen_saver.visible = false;

                part1_mc.visible = true;

            }

             

            //START EXECUTING SEARCH

             

            searchBtn.addEventListener(MouseEvent.MOUSE_DOWN, startSearch);

             

            var resultContainer:MovieClip;

            var resultCount:int = 0;

            var position:int = 1;

             

            function startSearch(event:MouseEvent):void

            {

                resultContainer = new MovieClip;

                part2_mc.addChild(resultContainer);

                disableButtons();

                ageStr = part1_mc.age_txt.text;

                heightStr = part1_mc.height_txt.text;

                genderStr = part1_mc.gender_txt.text;

                searchingDB.visible = true;

                part2_mc.visible = true;

                rightBtn.visible = false;

                leftBtn.visible = false;

                createResults();

            }

             

             

             

            rightBtn.addEventListener(MouseEvent.MOUSE_UP, moveRight);

            leftBtn.addEventListener(MouseEvent.MOUSE_UP, moveLeft);

             

             

            function moveRight(event:MouseEvent):void

            {

                if (position < Math.ceil(resultCount/3))

                {

                    resultContainer.x = resultContainer.x - 1680;

                    position++;

                }

                else

                {

             

                }

                checkRight();

            }

             

            function moveLeft(event:MouseEvent):void

            {

                if (position > 1)

                {

                    resultContainer.x = resultContainer.x + 1680;

                    position--;

                }

                else

                {

             

                }

             

                checkLeft();

            }

             

            function checkRight():void

            {

                if (position < Math.ceil(resultCount/3))

                {

                }

                else

                {

                    rightBtn.visible = false;

                    if (position > 1)

                    {

                        leftBtn.visible = true;

                    }

                }

            }

             

            function checkLeft():void

            {

                if (position > 1)

                {

                }

                else

                {

                    leftBtn.visible = false;

                    if (position < Math.ceil(resultCount/3))

                    {

                        rightBtn.visible = true;

                    }

                }

            }

             

             

             

            function createResults():void

            {

                var resultY = 250;

                var startX = 175;

                resultCount = 0;

             

                trace(ageStr.substr(0,2), ageStr.substr(3,2));

                trace(startArray[i][2]);

             

                for (var i:int=0; i < startArray.length; i++)

                {

                    if ((parseInt(startArray[i][2]) >= parseInt(ageStr.substr(0,2)) && parseInt(startArray[i][2]) <= parseInt(ageStr.substr(3,2))) || ageStr == "" || ageStr == "Unknown")

                    {

                        if ((startArray[i][4] >= heightStr.substr(0,3) && startArray[i][4] <= heightStr.substr(4,3)) || heightStr == "" || heightStr == "Unknown")

                        {

                            if (genderStr == "" || genderStr == startArray[i][3] || genderStr == "Unknown")

                            {

                                var resultItem = new result_item();

                                resultItem.name = "r_" + i;

                                resultItem.name_txt.text = startArray[i][1];

                                resultItem.gender_txt.text = "Gender: " + startArray[i][3];

                                resultItem.height_txt.text = "Height: " + startArray[i][4] + "cm";

                                resultItem.age_txt.text = "Age: " + startArray[i][2];

                                resultItem.description_txt.text = "                                " + startArray[i][5];

                                resultItem.features_txt.y = (resultItem.description_txt.y + resultItem.description_txt.height) + 20;

                                resultItem.features_txt.text = "Distinguishing Features: " + startArray[i][6];

                                var l=new Loader();

                                l.x = l.y = 0;

                                l.load(new URLRequest(startArray[i][0]));

                                resultItem.image_holder.addChild(l);

                                resultItem.y = resultY;

                                resultItem.x = startX;

             

                                if ((resultCount+1)%3 == 0)

                                {

                                    startX = startX + 780;

                                }

                                else

                                {

                                    startX = startX + 450;

                                }

             

                                resultContainer.addChild(resultItem);

                                resultCount++;

                                if (resultCount > 3)

                                {

                                    rightBtn.visible = true;

                                }

                            }

                        }

                    }

                }

            }

            • 3. Re: Desktop AIR Application installs fine on Mac... crashes on PC
              adobe_paul Adobe Employee

              Several months ago I worked on an app where I ran into a similar issue. A coworker (who uses Windows) wrote code that loaded an XML file using a URLLoader. Presumably it worked on his machine, but on my Mac it didn't work. I was never able to figure out exactly what the issue was -- it's probably a platform difference in the File.url property.

               

              In any case, for working with AIR it's best to use the FileStream class to read the contents of a file, rather than using URLLoader. The simplest way to do that is to replace this code:

              // LOAD AND PARSE XML

              var myLoader:URLLoader = new URLLoader();

              myLoader.load(new URLRequest(XMLDirectory.url));

              myLoader.addEventListener(Event.COMPLETE, processXML);

               

              function processXML(e:Event):void

              {

                  myXML = new XML(e.target.data);

               

                  for (var i:int = 0; i < myXML.result.length(); i++)

                  {

                      startArray[i] = [(imageDirectory.url + "/" + myXML.result[i].image), myXML.result[i].name, myXML.result[i].age, myXML.result[i].gender, myXML.result[i].height, myXML.result[i].description, myXML.result[i].features];

                      trace(startArray[i][0]);

                  }

              }

              Substitute it with this instead:

              var fileStream:FileStream = new FileStream();
              fileStream.open(XMLDirectory, FileMode.READ);
              var myXML:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
              fileStream.close();
              
              for (var i:int = 0; i < myXML.result.length(); i++)
              {
                  startArray[i] = [(imageDirectory.url + "/" + myXML.result[i].image), myXML.result[i].name, myXML.result[i].age, myXML.result[i].gender, myXML.result[i].height, myXML.result[i].description, myXML.result[i].features];
                  trace(startArray[i][0]);
              }

              (Adapted from "Example: Reading an XML file into an XML object" in the documentation -- you'll find more info there.)

               

              HTH,

              Paul

              Adobe Developer Relations/Documentation

              • 4. Re: Desktop AIR Application installs fine on Mac... crashes on PC
                fewremain Level 1

                Awesome! Thank you so much! I do believe with the previous project I was not parsing any XML so this is probably it. I'll let you know if this solves my problem, but I'm fairly certain you nailed it.

                 

                Thanks again!