AS2: Wait for actionscript to run before loading frame - actionscript

I have a script that takes lots of content and builds 1000s of MovieClips on the stage, does lots of drawing etc. Due to the high amount of work needed when the frame first loads this can sometimes be delayed by a second or two.
The more the user uses the application the longer and longer this is likely to be (more data to siphon through and build).
My question to you is how do I make sure the frame doesn't show (serve a loading image or something) until it is built? I don't want the user to see the skeleton of the page and then everything appear a second or two later.

The way we do it:
Frame 1 is a loading frame. It simply continually polls progress (onEnterFrame) until it is sufficiently "complete" to move on to the frame that is needed. In your case, it might be that you're testing to see if you've instantiated enough objects, in our case it was whether framesloaded was sufficiently high.
We often put a "loading graphic" in frame 1. Other than that we have the "am I ready to finally move on yet?". Most recently our loader just had a circle which continued rotating.
As a side note: wait until everything is completely ready if you're working with an AS3 loader. Loading half-cocked left me working until 3 AM on Easter one year. I was not happy.

Related

iOS CPU Activity Suddenly Dies

Long story here, so bear with me...
I have a view controller which, when presented more than three times throughout the life of an application session, will hang and lock and freeze my entire application. Even the Springboard locks up until my app's fully backgrounded! In Xcode's inspector, I noticed rather alarmingly that the memory footprint would jump a good 5-8 MB every time I presented that view, and it wouldn't go down again after dismissal. By the time the fourth invocation rolls around, the app's already using 40 MB of memory.
My first thought was, "OMG, itz a memry leek!" The second one told me to hop into Instruments and track it down.
While the Leaks tool did help some, it only told me that the app was leaking like crazy. All it would tell me was that, somewhere in these four second intervals, I had gained between "4 new leaks" and "17 new leaks." They did correspond to my opening that view, though, and once I started commenting random stuff (and following the sometimes helpful guidance of the Allocations tool), I tracked most of them down to three extra lines of code. "Oh well, I don't need those views anyway!" Those three lines no longer exist, and Instruments no longer complains.
My only complaint here is that my UI still behaves the same! On the fourth presentation, the entire app slows down. Upon further inspection of Xcode's instruments, I see that not only is the memory still going up (only to 30 rather than 40 MB this time), but the CPU activity has tanked!
Ok, granted I should have looked there in the first place, but I ain't perfect!
I ran the app again, and found that the overall CPU activity rose consistently the more I presented that view controller. By the third one, it was up to 40-60%. The main thread seemed pretty clear, and most of the activity was spread between eight other background threads (who knows what all those do).
The fourth time I opened that view, I had expected everything to block like crazy. It didn't. The CPU just... stopped. It was running at around 50-ish% when, by the time my finger had left the screen, it was down at 1%. All of the thread graphs shrunk from spiked stalagmites to tiny waves in a puddle. According to the pie chart, the vast majority of the processor was free to do as it liked. It doesn't like me.
I literally have no clue why it does this. I've been stuck in a room for days now trying to figure this out. Any help or advice would be much appreciated.
Does anyone have any idea why this happens, how this happens, or what I can do to make this not happen?? I'm drawing a blank here...
Thank you so much!
It should be noted that I got these by running the app on my iPhone 5s. Yes, I did try on the simulator, but my little MacBook Air took it like a champ, and was no help in figuring this out, except to tell me that the problem happened on iPhones.
I've run into this before, and the following is my general approach that usually allows me to fix these types of memory leaks.
First I would put a print statement into you viewController to see if your VC is being deallocated when it is being popped.
deinit {
print(self.description)
}
The next step, in the case that the ViewController is not being deallocated, I would start by removing core pieces, bottom up, commenting them out chunks one step at a time, yet leaving the back control that hides the view controller visible. Usually you can isolate the memory leak once you see the deInit get called after removing some code, you may have hit the part that made a strong cycle reference.
One more thing, ensure that all your delegates are declared weak, and search through your code for closures, and check that the closures aren't holding hard references within, especially to self.
Also, checkout this article to see the about using unowned or weak, when passing in instances into a closure, could be helpful.
http://krakendev.io/blog/weak-and-unowned-references-in-swift

Download images and show them in a slideshow

For the slideshow feature, the images are on a remote server, then can we implement a batch look ahead download of the images? We want say 'n' images ahead downloaded when an image is being viewed - this helps in providing a smoother viewing experience. Is this a good way to get zero latency for the slideshow or is there any better way than this.
To provide a smooth viewing experience as well as reduce (not zeroing) the latency for your slide show, I agree with caching mechanism.
I assume that you have a list of image urls, now as soon as the slide show displaying on the screen, start loading visible items. Trigger scroll view did scroll and load in the background the next n images after the last visible index, then cache them. So that whenever user scrolling to next indexes, images almost the time will be there in your memory and displayed instantly.
Why we should trigger scroll view did scroll. Firstly, because that is the idle time that allows you start doing things without user's notice. Secondly, if you start loading images while scrolling, at the time it is set to UIImageView, your slide show will be lag due to that task executed on main thread.
As the answer above, SDWebImage is a good library that can help you finish your task.
By the way, if you will consider of using SDWebImage, I would suggest you config this option
/**
* By default, image downloads are started during UI interactions, this flags disable this feature,
* leading to delayed download on UIScrollView deceleration for instance.
*/
SDWebImageLowPriority = 1 << 1,
I hope my answer will contribute 2 cents to solve your problem.
In my opninion, use SDWebImage https://github.com/rs/SDWebImage to preload images and clean memory cache if if exceed memory-limit.

iPhone SDK - possible to have multiple splash screens?

I'm making an app with a different screen for its first run. Once it has completed its first run, this screen is never shown again. The issue I have is that my launch image is built to look like the view that the user sees every other time they run the app, so at first run the loading screen looks weird. Is there any way to have one loading screen for first run and one loading screen for other runs? Thanks
You cannot have multiple or dynamic launch images. Even with the new storyboard/nib launch files, they are still quite static.
Make sure to open an enhancement report with Apple, requesting this feature.
In the meantime, consider a slight change of your flow to first display the initial view, and have an animation to display your first-launch view. This way, the transition will be smoother and more natural to your users.

Many UIViews + QLViewController = very slow performance

I am building a calendar control. It generally works well and is responsive, despite using hundreds of UIViews (each cell in the example image is a UIView).
http://i.stack.imgur.com/6g1hQ.png
I have run into a problem in which the calendar is put in an app. It is fully obscured by some other controls and finally by a Quick Look viewcontroller. When the Quick Look is dismissed it takes a long time (10 seconds) before the app appears to respond.
Any view other than Quick Look has no slowness symptoms
Any help would be appreciated.
The problem was Autolayout. It simply cannot handle more than a trial number of views. Each nested view impacts the rendering time exponentially.
I end up writing my own "MagicLayout" system that does the same job, but it takes about 500 ms instead of 10000ms. The amount of time to dismiss a ViewController went from 10 seconds to about 10ms
Coming soon to a Xamarin component store near you.

Jittery WebGL Scroller

I've built a scroller prototype using WebGL. The problem is, when it's combined with other non-WebGL elements on the same page, the scroller becomes jittery and the quality is quite poor. You can see a demo here (scroller is at the bottom, ignore the Chinese characters) - http://viewer-test.appspot.com/Viewer.html?type=presentation&id=6a169bb8-e440-4338-9e3a-8b5e429f32ee&showui=false Even if I take out the video, the scroller still slows when the CPU spikes every time that RSS feed top right shows a new feed snippet.
I had considered using Web Workers to run the scroller on a different thread, but came across another post in this forum that said that Web Workers can't be used with WebGL. What are my other options to ensure smooth scrolling?
Thx.
Are you using RequestAnimationFrame for your animation callbacks? If not, you should. It's managed by the browser to time the draw of your element with the others on the page and with the system screen sync, so you get the smoothest presentation possible. If you do your animation using setTimeout or setInterval, you'll almost always end up out of sync with the pages rendering, which leads to dropped frames and stutters.

Resources