Skip to main content
August 4, 2011
Question

AIR iOS app crashes

  • August 4, 2011
  • 1 reply
  • 1345 views

Hi everybody,

I've  been working on an iPad app in Flash and all went well but at the end I  discovered a problem. I'm making a childrens book with a page on each  frame. And a can move between the pages. On the pages things are  happening. Things can be touched and make sounds or can be moved.The  problem is that the app seems to be instable. After a while it crashes  and I have to start over again.

I did a lot of optimizing  as told at different blogs made sure all events are closed when I don't  need them anymore but it still crashes. Now I was thinking it could be the sound that is the problem. On each pages I load at least one sound some playing on click, endlessly looping when on the page. Could this give me a memory problem? I looked for sound and sounchannel close or remove options but couldn't find a right solution. I think it's easiest to put this remove sound stuff in the killMe function right? Here is a script I load everypage.

I'm working in Flash 5.5 with the AIR 2.7 SDK. And am testig on a iPad 3G.


Hope for some good tips or suggestions,

Thanks in advance.

Joost

package  {
   
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
   
    public final class konijn2MC extends MovieClip {
        //variables////////////////////////
        //import sound
        var mySound:Sound = new p18_sound();
        //
        var snd3Animal:Oceaan;
        var snd3AnimalChannel:SoundChannel;
        //
        //set frame number for random static motion
        var framePlacesSTAT:Array = new Array(10,10);
        //set delay time
        var maxTimeDelay:int = 7000; // 1000 is one second;
        var minTimeDelay:int = 5000; // 1000 is one second;
        var startTimeDelay:int = 1000; // 1000 is one second;
        var newTimeDelay:int = 0; // 1000 is one second;
        var timerSTAT:Timer;
        //set different static motion variantions
        var differentImages:int = 1;
        //
        //set frame number for touch animation
        var framePlacesTOU:Array = new Array(110, 110);
        //set frame delay for touch animation
        var frameDelayTOU:Array = new Array(300, 300);
        var countArrayTOU:int = 0;
        ///////////////////////////////////
        public function konijn2MC() {
            snd3Animal=new Oceaan();
            snd3AnimalChannel=snd3Animal.play(0,1000);
            addEventListener(MouseEvent.MOUSE_DOWN, touchFunc);
            addEventListener(Event.REMOVED_FROM_STAGE, killMe);
            //call random static animation
            stopstartSTAT();
        }
        //////////////////////STATIC functions/////////////////////
        function stopstartSTAT():void{
            if(timerSTAT){
                timerSTAT.stop();
            }
            //
            if(newTimeDelay == 0){
                newTimeDelay = startTimeDelay;
            }
            else{
                newTimeDelay = Math.round(Math.random()*(maxTimeDelay-minTimeDelay) + minTimeDelay);
            }
            //set timer
            timerSTAT = new Timer(newTimeDelay, 1);
            timerSTAT.addEventListener(TimerEvent.TIMER, timerActionSTAT);
            timerSTAT.start();
        }
        //
        function timerActionSTAT(e:TimerEvent):void{
            //if not touched go to random frame en play then start over again. go to function
            if(currentFrame < 110){
                gotoAndPlay(framePlacesSTAT[Math.round(Math.random()*(differentImages-1))]);
            }
            stopstartSTAT();

        }
        //////////////////////TOUCH functions//////////////////////
        function touchFunc(event:MouseEvent):void
        {
            stopstartTOU();
            mySound.play();
        }
        //timer function
        function stopstartTOU():void{
            //play frame number from array
            if(countArrayTOU == 0){
                gotoAndStop(110);
                countArrayTOU++;
            }
            else{
                gotoAndStop(0);
                countArrayTOU = 0;
            }
        }
        /* /////////////////////////////////////////////////////////
        KILL ME
        //////////////////////////////////////////////////////////*/
        function killMe(e:Event):void {
            removeEventListener(Event.REMOVED_FROM_STAGE, killMe);
            removeEventListener(MouseEvent.MOUSE_DOWN, touchFunc);
            if(timerSTAT){
                timerSTAT.stop();
                timerSTAT.removeEventListener(TimerEvent.TIMER, timerActionSTAT);
                timerSTAT = null;
            }
        }
    }
}

This topic has been closed for replies.

1 reply

Participating Frequently
August 4, 2011

Hi,

Could you verify that the crash is related to playing sound? Just comment the code that does it and see if you still see the crash. What are you displaying on stage? Could you check the value of stage.quality? In AIR 2.7, HIGH value of stage.quality is respected which didn't used to happen earlier. You might want to set to MEDIUM or LOW.(stage.quality = StageQuality.MEDIUM;)

What is the renderMode that you have specified - GPU or CPU?

If we can narrow it down to either of the two reasons above, you can log a bug at http://bugbase.adobe.com( with complete sources) and we can investigate whether you are running into some out of memory issue or it's a runtime bug.

Thanks,

Sanika

August 4, 2011

Hi,

Ill try the stage quality right away. The sound problem I will try but I it takes some time, there are about 28+ sounds loaded on different places at different moments.

I'm using CPU cause GPU gave me a crash aswell.

Thanks for the help