Please note that ExpatTech is close for the Christmas and New Year holidays. We will re-open on 2nd January 2024.

ExpatTech Techblog - optimization

Peter Todd 2011.04.14. 11:26

Trick for creating a list of your files

Have you ever wanted to have a list of your files? If you have to do a quick list of your files and / or folders, get the location of the files or folders. In Windows this can be done by right clicking on the parent folder, going to Properties, then checking Location. Copy and paste this text into your browser and see the list. Copy the list and paste it to your favourite text editor, word processor, or cellular data editing software (Excel, Google Spreadsheets etc).

Peter Todd 2011.01.17. 12:06

Flash Cookbook - Tricks - Conditional chains

 


Peter Todd 2011.01.17. 11:52

Flash Cookbook - Tricks - Shortening code

 

This trick is about shortening actionscript code.

Peter Todd 2010.10.28. 14:25

Flash Cookbook - CSS - CSS parser, parsing CSS StyleSheet and Style

Even though Flash has a built-in css parser, still it's not the best one. After running some tests it came out, it does not really support a lot of things. For example you can't use hyphen in declarations, nor you can use spaces in selectors.

These things are needed for our work, therefore the only way left is to write our own parser. In this post we write the basics - think it through, take it further and you will get a nice and handy class for your own.

Plus, the StyleSheet.parseCSS() method does not support styles not surrounded by curly brackets. This is what you can use in the attributes of an xml-tag: style="font-size: 15px". This wouldn't be understood by the built-in parser.

Peter Todd 2010.10.22. 12:43

Browser bookmark containing javascript

We can do a nice little tweak with the bookmarks. Bookmarks are usually used as bookmarks: they point to a web address. Browsers nowadays support add-ons or extensions and there is a huge palette of these nice little utilities helping us browsing faster and spend our time on the territory of world wide web. But for some people these add-ons (or extensions) are suspicious or some people cannot find the one they need for a task. A webprogrammer writes his/her own in this case, but what if the task we want to do is far easier then sitting down and struggling with an add-on (or extension).

Peter Todd 2010.10.08. 10:31

Flash Cookbook - Tricks - Super size bitmap, bitmapdata, infinite size

Today I ran into a problem. As we all know, Flash has a size limit on bitmapdata size.

Basically there are two rules to follow (see the specs):

Both the width and height has to be maximum 8,191 pixels

and

the amount pixels of the bitmapdata cannot exceed 16,777,215.

Well, well, well...

Peter Todd 2010.10.01. 10:49

Flash Cookbook - Tricks - Store data in bytearray and compress it

You can create a nice little drawing application using the flash graphics tools. Let's say you created an application, where you press the mousebutton, start to draw and draw lines by holding the button down. Every point your mouse reached is stored in an array at an ENTER_FRAME event.

This way I did a hand-drawn rectangle, consisting 36 points. If you want to save this drawing point by point, you save this array in the SharedObjects or send it to a server-side script to save it somewhere on the server.

Peter Todd 2010.10.01. 09:01

Flash Cookbook - Colors - Part 2. Invert Displayobject's Colors

To invert the colors of a displayobject you can use the transform.colorTransform property of the displayobject and apply a ColorTransform to it.

Peter Todd 2010.09.27. 14:22

Flash Cookbook - Appendix - Sort array indices

Yes. This is about array sorting. So there is the problem, that we want to sort an array, but want to know more about the indices. For this reason there is an option for Array.sort() function, which specifies the return value of sort():

Array.RETURNINDEXEDARRAY.

See the code below:

var array:Array = ["a", "c", "b"];
var sort:Array = array.sort(Array.RETURNINDEXEDARRAY);
trace(array, sort);

//a,c,b 0,2,1

It didn't sort the array, but returned an array with the sorted indices.

Peter Todd 2010.09.24. 10:10

Fun with Random - Part 2.

In the second part we create a static class for our random function, add a practical function and check whether it is really random.

Peter Todd 2010.09.23. 15:49

Fun with Random - Part 1.

Are you tired of the old randomgenerators? Here is a basic solution for creating your own.

Peter Todd 2010.02.01. 13:22

Flash Cookbook - Optimisation - Number types used for loops

In this section we will examine the speed of loops with the three number types.

Peter Todd 2010.01.29. 15:26

Flash Cookbook - Geometry - Fine tuning Point class Part 3. Angle.

"Dear Master,

if I can create a Point using the Point.polar() method, why on earth can't I reuqest the angle of a Point? Please answer me, you are my only hope.

The Little Grasshopper"

Peter Todd 2010.01.29. 14:21

Flash Cookbook - Geometry - Fine tuning Point class Part 2. Length.

Okay. Here we are with the second question. Can we fasten the request for length? - asked the little grasshopper.

Yes, we can. The result is a 15% speedup.

Peter Todd 2010.01.29. 13:45

Flash Cookbook - Geometry - Fine tuning Point class Part 1. Distance.

Point class is not a final class therefore we can extend it. To do this is quite useful because the main functions of points are in the package so you don't have to rewrite them. But still there are some extra things what you can override to get better results concerning speed.

Peter Todd 2009.07.03. 13:34

Flash Cookbook - Optimisation - optimizing flash code Part 2 - fast sine function

Using trignometric functions brings up a question of memory. Trigonometric functions are famous about slowing down everything... (if they're not, then we say it now).

The 50 point question is: is there a way to fasten Math.sin(x)?

The answer is yes, there is. But you have to consider one thing. Math.sin() function returns with a relatively high precision. Probably you won't find a way to override the speed of that precision, but actually, do we need that?

If you are not writing a high precision calculator, but handling pixel-level animations, how much do you need? Let's say first we want to reach a 4 digit precisity. This is what we have in mathematical tables, this is what people used over the centuries...

Peter Todd 2009.06.25. 13:33

Flash Cookbook - Optimisation - optimizing flash code Part 1.

This time we will go a bit deeper and see if flash code can be optimized (what a question!).

Of course it can be. We are not talking about single 1-2% optimization, but heavy stuff here.

Our frame code will be a counter and a cycle. For a million times we will run several algorithms, which in our case will give the same result - but not in the same time!