Archive for December, 2007

iFeedme Blog Already number 1 google result for “flex actionscript cute puppies”

Monday, December 31st, 2007

After only about 3 or 4 days! And with no actual cute puppy content so far … Google robots are busy busy bees, but no computer can recognise the presence or otherwise of bitmapped juvenile canine aaah factor :)

I am working on it, I really am…

Part of the problem is that I am currently on night watch for some actual puppies, but being pugs, a few days old, and black as well, they are not exactly very cute so far.

1 day old black pug puppy

More like something out of a rather dark Gothic horror film, to be honest.

At this tender age, someone has to watch over them lest they burrow under mum / mum sits on them / they blow mums milk out of their noses.
Any of which could mean a choked ex-puppy, so we watch 24 hours a day to the exclusion of programming,blogging and ,well, everything else really …

Number 1 google search for flex actionscript cute puppies

I do like the fact that I beat Aral Balkan into a miserable 3rd place though ! I’m sure He’ll have something to say about that…

Annoying bug in flash player ConvolutionFilter (maybe others?) with multicore processors

Monday, December 31st, 2007

I’m not quite sure where I report this one (mainly since I’ve made no effort to find out). Though Alex Harui was (I believe) going to file a report after I posted this to flexCoders.

Since some bitmap filter functions were made multi core aware and capable, I’ve been suffering the occasional line across the results of one the convolution filters that I’ve been using for edge detection of a colour in an image.

Reading Tinic Uro’s post here : http://www.kaourantin.net/2007/06/multi-core-support.html, it would seem that some bitmap operations are now split into two, and the results joined when both threads complete.

It would appear that there’s a edge case error in the flash player code to do with this.

The flex code below is a simple test case, for me it normally displays a horizontal line where there should be none with the first couple of dozen tries, but only on a multi core machine (windows, I don’t have a recent mac to test on :( )

It’s possible to set DisableMulticoreRenderer=1 in mm.cfg locally for ones flash player, unfortunately that’s not really an option for our clients.

Never mind, We are not releasing yet, it’s not a show stopper, and I’m sure it will get fixed in flash player in the future.

Download test case mxml here : Test case for multicore filter bug

See the test in action here : http://www.ifeedme.com/blog/customContent/filterbugexample/

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” width=”400″ height=”440″ creationComplete=”init()”>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.UIComponent;
private var _bmpData:BitmapData;
private var _bmp:Bitmap;

private function init():void
{
_bmpData = getTestBitmapData();
_bmp = new Bitmap(_bmpData,"auto",true);
var ui:UIComponent = new UIComponent();
ui.addChild(_bmp);
this.addChild(ui);
}

private function getTestBitmapData():BitmapData
{
var bmpData:BitmapData = new BitmapData(400,400);
bmpData.fillRect(new Rectangle(30,30,340,340),0xFFFF0000);
return bmpData;
}

private function testFilter(bmpData:BitmapData):BitmapData
{
var matrixX:int = 3;
var matrixY:int = 3;
var o8:Number = 1.0/8.0; //one eighth
var matrix:Array = new Array
(-o8, -o8, -o8,
-o8, 1, -o8,
-o8, -o8, -o8);

var col:uint = 0xFF00FF00;
var edgeFilter:ConvolutionFilter = new ConvolutionFilter(matrixX,matrixY,matrix,1.0,0.0,true,true,col,0xFF);

bmpData.applyFilter(bmpData,bmpData.rect,new Point(0,0),edgeFilter);

return bmpData;
}

private function test():void
{
if (! demonstrated)
{
_bmp.bitmapData = testFilter(getTestBitmapData());

var i:int = 190;
for(i=198;i<202;i++)
{
if (_bmp.bitmapData.getPixel32(40,i) != 4278190080)
{
demonstrated = true;
mx.controls.Alert.show("DOH! :( multicore bug found ??? \n See horizontal line artifact at \n Y = " + i);
}
}
}
}

]]>
</mx:Script>
<mx:Boolean id=”demonstrated”></mx:Boolean>
<mx:Button x=”5″ y=”405″ label=”TestFilter” click=”test()” enabled=”{!demonstrated}”/>
<mx:Button x=”85″ y=”405″ label=”Clear” click=”{demonstrated = false}”/>

</mx:Application>

mx:WindowedApplication StatusBar (showStatusBar)

Friday, December 28th, 2007

One of the things at the very bottom of my TODO list has been to remove that apparently useless 20 pixels blank bar that appears at the bottom of an AIR app by default.

I’d set it in my brain to “ignore for the moment, got more important things to think about” level, where it had remained for far longer than was healthy for it.

I think I’d had some sort of mental block as to what it was, because it wasn’t until something reared it’s little head in my tired synapses and shouted “It’s a status bar” completely out of nowhere, It had never occurred to me that an offline application would have a status bar by default. A browser, yes, but …
On subsequent checking, it seems that quite a few do, but oddly enough it’s something I’d never really noticed up until now, even after 10 years or so of using them. Wierd.

Anyway, to remove it set the attribute showStatusBar = false in your mx:WindowedApplication mxml tag.

I think that perhaps I should file this one under “LIKE DUH!” rather than AIR, perhaps?

At least I hadn’t posted the question to flexcoders and made an arse out of myself, like usual :)

Extracting an image(jpeg or png) from a raw ByteArray in actionscript / flex

Friday, December 28th, 2007

This is a question I see asked fairly regularly, yet it seems to be a hard one to google for and get an easy answer.

In my current main project I have a need to pre load a large amount of images as quickly as possible, and yet kill any existing preloads immediately should circumstances change. Some casting around lead me to the StreamLoader class which offers all I needed, with the proviso that the result is a raw ByteArray.

So, I needed a means to convert that ByteArray to a bitmap or BitmapData.

Some digging around lead me to the fact that the Loader class will do that for a ByteArray that is read from a jpeg or png file.

The code looked something like this for an existing ByteArray in a variable named “bytes” :

var loader:Loader = new Loader();

loader.loadBytes(bytes);

Now, the bitmap *will* be available in the loaders “content” property, but do not assume that just because you gave it a preloaded bytearray that it will be *immediately* available. Or you will be sad and confused, as was I :)

No, the bitmap will only be available once the loader.contentLoaderInfo complete event fires.

So, add an event listener for the complete event :

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);

Then get the bitmap from the loader at that point in time :

private function loaderCompleteHandler(event:Event)

{

var loader:Loader = event.target as Loader;
var bmp:Bitmap = Bitmap(loader.content);

}

Note that I’ve omitted all the usual removing of event listeners, unloading loaders etc for the sake of brevity.

So there you go, that’s how it’s done. Now I know the answer it makes perfect sense, but initially it did seem to work not quite as I expected it to.

Since then I’ve had occasion to use this a couple more times, such as getting a server side processed image from .NET via fluorine remoting services, and in AIR (grabbing images stored as ByteArray blobs in a sqlite database).

Getting all email addresses from an imap account

Friday, December 28th, 2007

I have need of grabbing all the email addresses (to, from, cc, bcc etc etc) from my current imap server.

The reason? spam. I’m moving my main email to this domain, it’s quiet and off the spammers radar, unlike orange.net.

However, I’d like to have a plain text file detailing all the adresses I’ve communicated with over the past few years, such that I can unsubsribe the lists I no longer read, inform my friends I’m moving address, change my online shopping registrations , build a white/blacklist for forwarding from the old email address, etc etc.

I was quite surprised how hard it was to google for a small program/utility that did such a thing, in fact I failed to find one.

I ended up in php’s imap functions documentation, and from there it was pretty quick to script it.

Job Jobbed, as they say. Except for the need to find some sort of nice code formatter for wordpress ….

<?php
$imapServer = “{imap.yourserver.com:143}”;
$userName = “your.username”;
$password = “secretsquirrel”;
$mbox = imap_open($imapServer,$userName ,$password );

$folders = imap_listmailbox($mbox, $imapServer, “*”);

imap_close($mbox);

if ($folders == false) {
die( “failed to get folders\n”);
} else {

$addressArray = array();

foreach ($folders as $val) {

$mbox = imap_open($val, $userName,$password );

$numMessages = imap_num_msg($mbox);

print(”there are $numMessages in the mailBox $val\n”);

for($i=1;$i<=$numMessages;$i++)

{
$headerInfo = imap_headerinfo ($mbox,$i);

foreach($headerInfo as $headerObj)
if(is_array($headerObj)){

foreach ($headerObj as $id => $object) {
if(isset($object->mailbox) && isset($object->host))
{
$address = (string)($object->mailbox . “@” . $object->host);
if(array_search($address,$addressArray )=== FALSE)
{
$addressArray [] = $address;
}
}
}
}

}

imap_close($mbox);

}
}
$numAddresses = count($addressArray);

for($i=0;$i<$numAddresses;$i++)
{
print($addressArray[$i].”\n”);
}

?>

New Year, new Blog

Thursday, December 27th, 2007

To add to the few that I’ve abandoned in the past.

Anyway, this time it’s wordpress, which was at least ridiculously simple to install.

Expect (hopefully) a few occasional posts on flex, actionscript, mxml, fluorine web services and the like.

And possibly some pictures of cute puppies.