May 17 2009

Extracting image binary info without loading the entire file

Category: ClassesHadi Tavakoli @ 10:37 pm

Well, today I surely teared myself apart! I spent about 10 hours to get myself femiliar with how the three most popular image formats, jpg, png and gif work and how we can use the flash AS3 ByteArray class to extract this information!

I must confess that I still am very unclear about a lot of different things in byteArray class but the least I managed was to find and combine some classes and finally managed to output the kind of information I needed.

Before anything I must thank to Antti, who wrote the beautiful class of how we can read and use binary data of jpg file. you may read his artical here.

The problem with Antti class was that his class supported jpeg format only and didn't extract all the other information I needed and actually was too bugy for my needs!

So, I had to do some more searches here and there and I found this other artical here which did made me happy by how it extracted image info and it supported all the three formats. but the problem with this latter class was that it actually extracted all the data just after it loaded the whole file entirely! which in practice makes it useless, at least for my purpose.

So, I have the two classes, one tells me how to search for the information I need the other one tells me how to kill the loading process as soon as I found out the information I was looking for!

ok, good, finally what I did was to combine the two classes together and build a new class which you can download here:
http://emstris.com/sample/AS3/byteArray/ImageInfoExtractor.as
(simply put it in your class files in this location: com\myflashlab\classes\tools\imageEncoders)

and using this new class I put together, you can find out a lot of information about images before they are downloaded entirely :) actually this information gets extracted in just a second! maybe less than a second.

you will be able to use the above class like this:


		  
		  
		  
		  
		  
		  
		

looks nice and clean, right? yeah, this will be absolutly useful in big and complex projects.
I have also a sample online, check below and see how the class has extracted the information out of the big image, about 800 kb, in just a second! and kills the connection right after that.

 

I hope you enjoy the class. just one thing, I would really love to be able to find out the header binary information of a swf file also. if anyone managed to update this class so that it also supports .swf input, I'd be more than happy to have it also :)

Thanks,
Hadi

Tags: , , , , , , , , , , , , ,


Feb 12 2009

AS3 itemList Class V 1.0

Category: itemListHadi Tavakoli @ 1:27 am

in my other post we created a Box class http://www.emstris.com/category/classes/box/ where we managed to set a box of information with actually three elements, a thumbnail, a title and some space for the details.

In that Box class you where able to create any size boxes and put anything in them but using that class alone will not be very helpful if you are trying to build a playlist or something! right?

So I thought of creating an itemList which can easilly add these boxes in a class which will extend MovieClip so it will be a lot easy to pile up the boxes and insert data into them.

let's take a look at our itemList now:

And with the help of below code we will create new instances of our item list:


		  
		  
		  
		  
		  
		  
		

This ItemList class is actually a MovieClip as we are extending MovieClip and it can be placed anywhere. As you see above we have first initialised the class and then have set diffrent properties to be used later in every instance of the Box class which we will later import through the ItemList class.

Take a look at the ItemClass itself and you will find a couple of interesting things around... hehehe, maybe you won't call creating of custom listener an interesting thing! but as this is actually the first time I am creating them, I am very excited that I am planing to post a complete new topic about them! Anyway, here is the item list class:


		  
		  
		  
		  
		  
		  
		

If you ask me to summarize the whole thing, I can say that all this item list class does, is to create new instances of the Box class and insert the data into them! But I also added a couple of useful features into it like how you click on an item and it gets highlighted, and how you can set one of the items as the default selected item, and also the most beautiful part from my eyes which is the "dispatchEvent(new Event("itemChanged"));" :) As promised, I will talk about how custom event listeners work later in my next post.

ok, You may download the complete item list class from here. (Saved in CS4)

After you play a bit with this item list I am sure you will quickly say that this item list will look better if we can put it under a scrollbar... yeah, of course you're right, and why don't you do that yourself?! :D

in my scrollbar class here I have made it in a way that enables you to drop any movieclip under the scrollbar so why don't you try and drop the item list under it? well, later when I post my dropdown menu class, you will see how we are managing to combine all of our different classes and put them all work together in a dropdown menu! keep checking back and you will see some more useful stuff around here... I guess we are really making a progress in AS3 ;)

Regards,
Hadi

Tags: , , , , , , , ,