Archive for the ‘Tips’ Category

My Mistake With readBytes in AIR

I was trying to read a specific part of a file in AIR. I thought readBytes function in FileStream can serve the purpose but I was wrong.

public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

Reads the number of data bytes, specified by the length parameter, from the file stream, byte stream, or byte array. The bytes are read into the ByteArray objected specified by the bytes parameter, starting at the position specified by offset.

The offset parameter is defined as the offset position in bytes. It defines where to store the data in bytes not where FileStream starts to read. The correct way is to move the FileStream.position and specify the length fo data needed.

i, for loop, uint and int in ActionScript 3

Defining i:uint is not better than i:int since both of them take the same amount of memory. Besides, it’s risky to define i:unit because if i is accidentally assigned to a negative value it becomes a big positive int.

Reading Excel generated XML with ActionScript 3

Excel files can be saved as XMLs. In ActionScript 2, reading Excel generated XML (EGX) files is really tedious and unreliable because EGX files’ data hierarchy is not fixed and they have lots of formatting/styling information. To ensure not missing any data, it requires traversing every single node. It’s very inefficient. With AS3, its XPath like approach allows to find nodes located anywhere in the document by using the “..” notation which is “//” in XPath (ActionScript 3 changed all the “/” into “.” which makes more sense for object oriented programmers”. But that’s not all for reading EGX files. (more…)

Text Formater: for lazy people

I think many programmers have encountered such situation: you need to modify some large amount data in plain text into a useful format, things like creating 1000 links in HTML based on 1000 web addresses, or generating some test data running in sequence user1, user2, user3 etc. This small Flash can do it for you. (more…)

Flash Upload File with ASP.NET

Uploading file from Flash to PHP through FileReference is fairly simple.

move_uploaded_file($_FILES[’Filedata’][’tmp_name’], $_FILES[’Filedata’][’name’]);

You can easily find it in any Flash upload file related tutorials or posts. But I spend almost one hour searching for a solution of how to upload file from Flash to ASP.NET.

dim myFile as HttpPostedFile=Request.Files(0)
myFile.SaveAs(Server.MapPath(myFile.FileName))

That’s it. Seems fairly simple. It’s in VB and the C# version you can get from The Algorithmist

It looks like something like this:

foreach(string fileKey in _context.Request.Files)
{
HttpPostedFile file = _context.Request.Files[fileKey];
file.SaveAs(Path.Combine(uploadDir, file.FileName));
}

3 Firefox add-ons that a Flash developer must get

Web Developer Tool Bar : I find the resize function is very useful.

Tamper Data: If a Flash website involves loading external data or communicating with backend scripts, this is a tool helps to see what Flash is doing.

Flash Tracer: Displays Flash trace function results in FireFox. The setup procedure is in this blog entry.

Flash best practice: stage dimension 1000×570

Before starting on the design a Flash website, first thing first, the dimension of the file must be decided. Even full browser flash (FBF) sites can’t run away from this. I’ve seen sites that have overlapping text due to wrong dimensions, such as this new FWA site. (more…)