Quick Tip: AIR 2.5 & Security.loadPolicyFile()

After switching my AIR application into new AIR 2.5 SDK, boom! Every single URLRequest threw an IOErrorEvent. No other exception thrown. So I started digging in in order to find the cause and it appeared to be Security.loadPolicyFile() execution (I am reusing some libs containing these lines) that blocked it all quietly. First I tried to do try-catch block over it, but with no success. Than I just removed the lines for AIR project and voilà, everything back to normal again. URLRequests works again. It seems like AIR does not need loadPolicyFile() for URLRequests at all. Interesting that these loadPolicyFile() were targeting total different domain and were able to break any other requests.

Processing BitmapData.getPixels() With PHP

Have you ever worked with BitmapData.getPixels() method? This method generates a byte array from a rectangular region of pixel data. Writes an unsigned integer (a 32-bit unmultiplied pixel value) for each pixel into the byte array. Thats sounds good, but what is it good for to have a ByteArray full of integers? There is not even a decoder for this format on my backend?!… Well, this format is so cool, and easy to access that you do are able to write your own decoder e.g. in PHP.

The resulting bytes are 32-bit unsigned integers for each pixel represented by AARRGGBB format, followed by another pixels and so on e.g.:

AA RR GG BB:
-- -- -- --
FF FF 00 00
00 00 FF 00

Read the rest of this entry »

Quick Tip: stage.mouseX on Android

When working with AIR on Android, I felt into an issue with stage.mouseX (stage.mouseY) returning value 107374182. It seems I am not the only one who experience that, but also Michael Ritchie and Lex Talkington did. This happens after you release touch screen. You may expect that Event.MOUSE_LEAVE would be fired in the right moment, but that sometimes just does not (sometime it does). I did not found any better solution than testing returned values against the static number, so I came up with this piece of code:

if(stage && (int(Math.abs(stage.mouseX)) == 107374182
    || int(Math.abs(stage.mouseY)) == 107374182))
    return;

Debug & Deploy Flash on Android

It is now a few weeks after I started experimenting with AIR for Android. While watching all the great tutorials about how to make things work (AIR for Android – Part 1, Part 2) and how to debug application running on device (Debug AIR apps on Android with Flash Builder 4, another in french and Flash), I have decided to attach some of my own findings and practices to build, deploy and debug apps.

To start, it is a good practice to setup your environment variable path to Android sdk and AIR sdk:

PATH: ...;C:/Users/Yoz/Work/Android/SDK/2.2;C:\Program Files\Adobe\Adobe Flash Builder 4\sdks\4.1.0.16076-AIR2.5\bin

Next, the whole certificate thing does not make sense to me because you can/have to create one by yourself. The cert need to be valid for 25 years else Android Market will not accept your application (bye bye real signed certificate from PGP TrustCenter :-( )

Read the rest of this entry »

Authorizing Facebook Applications in Android

Hold on, this is going to be fast and smooth! I am playing with an Android Emluator for a few days now. One of the challenges was to mount FacebookOAuthGraph lib into Android. It turned out to be 1 hour task. Thanks to Flash-Core article and sHTiF and StageWebView. Long live AIR for Android! :-) Follow the article for codes:

Read the rest of this entry »

Quick Tip: AIR Application Without Flex Framework

This may be pretty known thing, but I would like to share it. When creating a new AIR project in flash builder (File / New / Flex Project / … Desktop – AIR), and you do not require flex framework, just rename the “Main application file” to whatever.as (instead of whatever.mxml) in the last step of creation wizard (screenshot attached). Or, if your project already exists with main app.mxml file, just create new file with the same name app.as and remove the old one (app.mxml). Make sure your main application class extends Sprite.

Superfast 3D Scene Without 3D Engine

Based on my previous post about z-sorting indices, I have created a superfast 3DDM version using drawTriangles(). The following example renders 100×100 segments = 10201 vertices = 20000 triangles (faces) per frame. Just to imagine how much that is, see the main image fullsize. There is no 3D engine used at all, everything is handled by native flash classes and functions. Z-sorting is not calculated on every frame (however it could be, because the sort algorythm is pretty fast), but it is pre-cached for some rotation. Feel free to run the example in new window in order to see the real speed (there is more flash content around here on my blog template). I can go up to 12 fps with the best flash quality for the first image in demo, how much can you?

Read the rest of this entry »

Z-sorting Indices For drawTriangles()

While constantly improving 3DDM (drawTriangles() version soon to be released), I was looking for the fastest possible solution to render simple 3D object. It soon appeared to be drawTriangles() – the native ActionScript 3 method, that let you make illusion of 3D object based on deforming your texture. In fact native ActionScript contains a lot of useful and fast classes to work with 3D like: Utils3D, Vector3D, Matrix3D, PerspectiveProjection… so you do not need to create your own basic 3D engine tools. One thing that it does not contain is z-sorting. Z-sorting is very tricky job, that is why modern 3D engines let you decide which sorting method to use with your scenes (faster vs. precise). For my needs it is enough to use simpliest z-sort possible, based on projected max z coordinate of face (3 vertices).

Before continue reading, make sure you understand the basics of Using triangles for 3D effects, Transforming bitmaps, UV mapping and Culling. Everything is very good described by Adobe.

Read the rest of this entry »

Get Adobe Flash playerPlugin by wpburn.com wordpress themes