Archive for March, 2009

Downloading file parts with AIR

I just found out something cool using URLRequestHeaders in AIR.

Using the “Range” header, you can download specific part of a file.


var urlLoader:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest("http://upload.wikimedia.org/wikipedia/commons/f/f2/Fanciful_Landscape-1834-Thomas_Doughty.jpg");
urlRequest.method = "GET";
urlRequest.requestHeaders = [new URLRequestHeader("Range", "bytes=0-99")];
urlLoader.addEventListener(Event.COMPLETE, loaded);
urlLoader.load(urlRequest);

function loaded(e:Event):void{
trace(e.currentTarget.data);
}

In this example above, it will load just the first 100 bytes of the file.

I don’t know if there is other ways to do it, but, at least it worked fine for me.

With this, you can manage downloads for huge files pausing and resuming not loosing datas.
Like, if the internet connection breaks while you are downloading something, you can simply resume after the internet connection comes back.

Vote in HexoSearch Vote

Comments (3)

MathUtils Class

Hi,

After a long time, I uploaded a class in my SVN.
http://code.hellokeita.in/public/trunk/as3/br/hellokeita/utils/MathUtils.as

It’s a small class br.hellokeita.utils.MathUtils.
Inside, there are few methods: combination, factorial, solveCramer and squareMatrixDeterminant.
I think method name tells what it does, so please check it out and comment about it.

cheers,
k

Vote in HexoSearch Vote

Comments

Multi Bézier Curve

What is Bezier?
Simply explaining for dummy AS programmers, is what graphics.curveTo method does.
If you want to learn more, here is the Wikipedia article.

Basically, the curveTo method uses a quadratic bézier, so you need a control point and a anchor point.
But it’s difficult to find the precise control point for a curve you want, because the control point is not inside the curve.
Also, you just can create a curve with just one control point, or if you want to use many curveTo methods in sequence, sometimes the curve doesn’t became as straight as you want.

So, I created a class that calculates the control points with multiple values bézier.
You can also get the position in this curve.

Here goes the examples. (you can click and drag the points)


This is an example using 7 positions, the start and the end anchors and 5 control points.
In the class, there’s a method that returns me an array with the approximated quadratic bézier values, so I’m using this values to draw the green line.
You see that it still hard to draw a path that you want.


This is the same example, but now the positions are inset in the curve.
Now, it became easier to create a curve line.


And here, a animation over the curve.

Sorry for lack of explanation, actually I’m in vacation now, but I wanted to post this class.
Later I’ll try to post more examples and uses.

I will try to update my svn with these classes, commented, after I came back from vacation.
So, for now, here is the source code.

Vote in HexoSearch Vote

Comments