Adventures in AIR

So I’m getting back to trying to learn AIR. I had originally written a few small apps way back when it was in alpha, so now I’m learning the release version. It’s surprisingly simple. My goal with this app was to play with the saving of bitmaps to the hard drive, and it turned out to only require 8 or so lines of code.

1
2
var bd:BitmapData = new BitmapData(targetCanvas.width, targetCanvas.height, false);
bd.draw(targetCanvas);
1
2
var jpgEncoder:JPEGEncoder = new JPEGEncoder(75);
var imgByteArray:ByteArray = jpgEncoder.encode(bd);
1
var fs:FileStream = new FileStream();
1
2
3
4
5
6
7
8
9
try{
fs.open(file, FileMode.WRITE);
fs.writeBytes(imgByteArray);
fs.close();
}catch(e:Error){
Alert.show("Error saving file :( : " + e.message);
return;
}
Alert.show("File Saved.");

I’m also using the AS3 Flickr API from adobe, which is another thing I haven’t played with yet. I’m finding the documentation for the flickr api to be slightly less than spectacular, it doesn’t seem to actually match up with how the API works, but I did manage to get a search of creative commons licensed photos working.

Anyway, check it out. It’s still in progress, so please let me know if you find any bugs, or just have suggestions for improvement.

AIR Lolcat Generator

Posted in Misc. | 1 Comment

the Dictionary Object

Ever run into the problem of passing data with your MouseEvents? You can’t store data in your MovieClips, Sprites, whatever, without creating a custom class, and sometimes creating all those custom classes is a bit more than you need.

Enter the dictionary object:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Dictionary.html

The dictionary object allows you to store variables like in an associative array, but instead of using strings as keys, you can use objects.

Construct your dictionary object. Passing true tells the dictionary object to use weak references, it’s false (strong) by default

1
var myDictionary:Dictionary = new Dictionary(true);

Set up your objects, storing the appropriate data in the dictionary object. (In use, this data would be pulled from xml or something)

1
2
3
4
5
6
for(var i:int=0; i<10; i++){
var temp:Sprite = new Sprite();
myDictionary[temp] = 'my random data';
temp.addEventListener(MouseEvent.CLICK, clickHandler);
this.addChild(temp);
}

Then your mouse event handler can easily access the data!

1
2
3
protected function clickHandler(e:MouseEvent):void{
trace(myDictionary[e.currentTarget]);
}
Posted in Misc. | Tagged , , , | 3 Comments

naughty, naughty uints.

I stumbled across this helpful analysis of ActionScript 3.0 Optimizations while reading about bit operations last week. I think some of you might find it useful. I find it interesting (as I mentioned in my class last night) that uint, unlike in other languages, is remarkably inefficient. Having learned java once upon a time, I was totally excited about the addition of ints and uints… but for now I’ll have to stick to ints.

http://rozengain.com/?postid=35

A friend likened optimizing actionscript, to judo skills:

There is a Japanese expression that is actually the main principal of Judo which is “Seiryoku Zenyo” translated as “maximum efficiency with minimum effort”. 

Posted in Misc. | Tagged , , , | 1 Comment

welcome to actionscriptgirl.com

Welcome! This is my second attempt at a blog,  ever, I’m hoping this one will be less of a miserable failure than my first one. Hopefully, this time around I’ll be a bit more diligent about posting on a regular basis.

In general this blog should contain my general thoughts about ActionScript, problems I’ve run into, and neat things I’ve stumbled across on other blogs… all relating to ActionScript.

If there’s anything you’d like to see me write about, please let me know!

Posted in Misc. | Tagged | 2 Comments