Skip navigation
JayCH74
Currently Being Moderated

Simple App - Huge Lag. Please Help.

Apr 15, 2011 4:02 PM

So I have built a simple app that has 40 frames in the timeline. On each of those frames, I have an 2 images (PNG format) at 320x480 that come in at about 15kb each. I also have a block of text and 3 buttons. One button calls to an event that sets the visibility of the top image to 0, revealing the image underneath. Another click of that button sets the image visibility back to 1. The other 2 buttons control clicking back and forth between frames (previous and next buttons). Altogether I have 100 PNG image files in my app. I have imported the images into the library and they are physically in the timeline as opposed to being pulled in via ActionScript. The ActionScript for the buttons is done once and stretches across all 40 frames - it is:

 

btnMagnify.addEventListener(MouseEvent.CLICK, onClickMag);
btnPrev.addEventListener(MouseEvent.CLICK, onClickPrev);
btnNext.addEventListener(MouseEvent.CLICK, onClickNext);

 

function onClickMag(event:MouseEvent):void {
    if(myZoom == 0){
        imagefull.visible = false;
        myZoom = 1;
    } else {
        imagefull.visible = true;
        myZoom = 0;
    }
}

 

function onClickPrev(event:MouseEvent):void {
    var myNum = currentLabel.split("-");
    gotoAndStop("pg-" + (int(myNum[1]) - 1));
}

 

function onClickNext(event:MouseEvent):void {
    var myNum = currentLabel.split("-");
    gotoAndStop("pg-" + (int(myNum[1]) + 1));
}

 

My problem is that when I export this to my iPhone, it takes about 4 seconds when I click on one of those buttons before it reacts and does what I want. If I cut down the number of frames (and, thus, images used) it increases the speed at which it performs. Should I be loading these images into the movie in a different manner so performace can be optimized on the iPhone? I've been working with Flash for several years, but this is my first iPhone app using it and I can't understand why the SWF works fine but the iPhone app is so slow. Any help or advice would be GREATLY appreciated.

 

Thanks!

 
Replies
  • Currently Being Moderated
    Apr 15, 2011 5:55 PM   in reply to JayCH74

    Are you using the Old Iphone Packager Built into flash.Or are you using the new AIR 2.6 build?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2011 4:54 AM   in reply to JayCH74

    Yes this is a big problem, so use caheasbitmap or caheasbitmapmatrix and cpu or gpu acceleration in your publish settings. But if you iphone is a 3g ( first generation before 3gs) it will always be slow : 4 second seems to be very slow for small graphic.

     

    putting all image in an array and load them with urloader couldbe also a solution but full screen image and full text page cause the app to be slow.

     

     

    I never use air 2.6 butI am not shure this will for sure increase performance. Try it


    have a nice day

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2011 9:02 AM   in reply to JayCH74

    As an aside, you should look at currentLabels. If you use that you ought to be able to navigate forward and backward through framelabels without needing to know thier names.

     

    Back to the main problem, if you are using 3G (you haven't said, but just in case), then AIR 2.6 isn't an option.

     

    The thing that takes the longest time is the caching of large bitmaps onto the graphics memory, and in your case that's what you're doing all the time. The size of the original PNG doesn't matter, it's the width and height of it that affects the transfer time. If you are currently setting cacheasbitmap and cacheasbitmapmatrix, I would try turning those off, and set the publishing settings to use CPU. The reasons you would use those is so that you can get graphics onto the graphics memory and move them around quickly, or scale and rotate them smoothly. If you're just setting the visibility, then that can be handled in regular memory, and the graphics card will just get updated when the stage refreshes.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 18, 2011 9:13 AM   in reply to JayCH74

    Do you use cacheasbitmap at all? Did you try turning that off and doing an AIR 2.6 CPU build?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 19, 2011 11:55 AM   in reply to JayCH74

    Forget the timeline and do something like this:

     

    Import your images to library and turn on Export for Actionscript, name your images and create an array:

     

         private var bgImgArr                    :Array = new Array("bg_abstract", "bg_bamboo", "bg_bars", "bg_candy");

     

    Write a method similar to this:

     

            private function setBgImage(str:String):void
            {
                if (currentBgImg && this.contains(currentBgImg) ) removeChild(currentBgImg);
               
                var bgClassReference:* = getDefinitionByName(str);
                var bgInstance:BitmapData = new bgClassReference();
               
                currentBgImg = new Bitmap( bgInstance );
                addChild(currentBgImg);
            }

     

    Call it like this:

     

    setBgImage(bgImgArr[ SOME_INDEX ]);

     

    Runs smoothly on iPhone 3G with any number of images. I just used similar approach in my latest iPhone game Blockslide: http://itunes.apple.com/us/app/blockslide/id431490534?mt=8&ls=1

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points