February 13th, 2008 . by polyGeek
I’m working on an image browser to go along with a video player. I noticed that after browsing to the 12th image the loading slowed down considerably.
When an image is replaced it fades to 0 and the image that gets loaded fades to 100. Nothing I haven’t done countless times before.
To fix the slow loading after the 12th image I tested a few things. First I made sure that my reference to the imageLoader was cleaned up. It was. Yeah me. :-)
Then I tried removeMovieClip on the image that faded to 0. That fixed it. Problem is that now I have to load each image every time instead of just fading it back to 100 if it’s already been loaded.
Then I tried setting the visible = false after the image had faded out. That worked. Everything runs smooth.
I would have thought that an alpha = 0 would take that object out of the rendering list but I suppose it doesn’t. If you don’t want the Flash player to be rendering an object set it’s visibility to false.
Posted in Actionscript 2.0, Actionscript 3.0, Code Optimization
|
5 Comments »
February 11th, 2008 . by polyGeek
I’m about to rewrite my LiquidText class in AS3 but first I thought I’d apply some of the code optimizations to the AS2 version and add some API calls to adjust settings just in case someone wants to use it.
Here’s an example of it in action below [ download FLV | download LiquidText.as ]
Essentially, what LiquidText does is it takes the text that you give it and breaks it down into an array of the individual words. It then finds a place where it can put the first word within the area that you specify without hitting any of the shapes that it wraps around. Then it places the following words until it runs out of space on that line. Then it wraps to the next line and starts the process over again.
Posted in Actionscript 2.0, Code Optimization, Portfolio
|
5 Comments »
October 15th, 2007 . by polyGeek
Everyone wants to optimize their code so that it will perform faster and give the user a smoother more entertaining experience with their RIAs and cool 3D sites created with Papervison3D. But have you ever stopped to think that by its very nature optimized code uses fewer CPU cycles and therefore less energy. In doing so you reduce the amount of carbon dioxide in the atmosphere.
So here are a few tips to optimize your code and save a few icebergs in the process.
When iterating through an array you should declare the length of the array outside of the for-loop as such:
var len:int = someArray.length;
for( var i:int = 0; i < len; i++ ) {...
You can apply that to AS2 by declaring len as type Number.
In AS3 never use Math.floor. It’s slow as frak. Instead cast the number as a type int as so:
var someDecimalNumber:Number = 3.14159265
var someNumber:int = int( someDecimalNumber );
And my favorite is instead of dividing you should multiply by a decimal as such:
var halfWay1:Number = ( endX - startX ) / 2; // slow
var halfWay2:Number = ( endX - startX ) * 0.5 // fast
Or if you really want to burn rubber then when multiplying or dividing by 2 you can use the binary right or left shift operator. As such:
var half:Number = 123 >> 1; // same as dividing by two
var twice:Number = 123 << 1; // same as multiplying by two
Note: using right-shift to divide outputs an integer so it only works accurately with even numbers. Example 7 >> 1 = 3.
There are lots more great ideas here at OSflash.
Now go out there and write optimized code. If not for your users then think of the polar bears.
Posted in Code Optimization
|
17 Comments »
August 26th, 2007 . by polyGeek
One of my hobbies is playing around with mathematical algorithms in Actionscript. Here are a few sites I have found useful.
Code Optimization
AS3 Speed tests
This is a community maintained page of speed optimization techniques for use with ActionScript3.
AS3: Rethink your old assumptions
A bit on code optimization using constants and variables.
Fast and accurate sine/cosine approximation
More code optimization to do sine/cosine operations without using the Math class.
Bitwise gems - fast integer math
Using bitwise operations to speed up calculations.
Actionscript
Using molecular mechanics in Flash
Cool motions based on equations of attraction and repulsion.
Making Bitmap Art with Flash CS3 and WikiPedia
Art from equations.
Sites
Wolfram’s MathWorld
The web’s most extensive math resource.
Superfractals
The site resource for the book Superfractals by Professor Michael F. Barnsley
Good Math / Bad Math
Finding the fun in good math. Squashing bad math and the fools who promote it is their tagline. I just hope he never writes about me.
Articles
Iterated Function Systems and Attractors
Covers the mathematical iteration I used here.
Posted in Actionscript 3.0, Code Optimization, Mathematical Algorithms
|
2 Comments »