Undocumented Flex goodness 3

When using Drag-and-Drop enabled controls, you can use a public function called calculateDropIndex(event:DragEvent) to figure out where Flex will drop the element being dragged. This method is part of the ListBase class and is overridden for TileBase (which extends Listbase but is the superclass for containers that layout stuff horizontally).

Flex Tip: Changing the source of an ArrayCollection 4

Here is a quick tip for Flex newbies although I imagine this is something thats fairly obvious. If you want to change the complete dataset of an ArrayCollection, do not create a new ArrayCollection object pointing to the same variable(well you can, but it will kill all the databound controls that are listening to events on the ArrayCollection instance). Instead use arraycollection.source = [ ... ] to repopulate the source value with a new Array. This will broadcast a CollectionEvent with the 'kind' property of the event set to 'RESET' and keep all the controls in sync. CollectionEvents are broadcasted everytime the values in an ListCollectionView instance are changed (ArrayCollections extend ListCollectionView).

I just saw this bug on an application I was working on where the controls kept getting out of sync with the core data in the ArrayCollection and this was the culprit ! The code looked something like this:

Actionscript:
  1. [Bindable]
  2. public var dataAC:ArrayCollection;
  3.  ...
  4. private function onDataLoaded(evt:Event){
  5.    dataAC = new ArrayCollection(parseIntoArray(evt.data));
  6. }

So everytime the new data came in, databinding was destroyed. The correct solution should have looked like:

Actionscript:
  1. [Bindable]
  2. public var dataAC:ArrayCollection = new ArrayCollection;
  3.  ...
  4. private function onDataLoaded(evt:Event){
  5.    dataAC.source = parseIntoArray(evt.data);
  6. }

Hope this saves some time for someone :)

Woohoo…DiggGraphr is a finalist at the Digg API contest and is featured on TechCrunch !!! 1

This is amazing. My apollo application is one of the 10 finalists in the Digg API contest. But it gets even better: Techcrunch did an overview of the 4 apollo based entries and only mine has a screenshot up there :) (yay! I am special). I am not going to win the contest itself but I never imagined I would ever be on Techcrunch!!! This rocks !

Check out the DiggGraphr application here and digg it if you like it.
The TechCrunch article can be found here
For more info on DiggGraphr, check the info page here

And here is a screenshot saved for posterity

DiggGraphr on Techcrunch

My entry for the Digg API contest: DiggGraphr Desktop 0

I just submitted by entry for the Digg API contest. Building on my earlier DiggGraphr tool, I was fairly easily able to port it to Apollo. I even added some customization features, like refresh interval and stuff. For more details on the application, check out the application page here. Feedback is always welcome :)

PS, it took me a while understanding some file metaphors that apollo has. So this is just the first version of the application. Hopefully, I will add more features to it soon :) .

My first useful Apollo app… 2

This is for a project I am working on and it works pretty sweet. There were a few lessons learnt during the development of the app so I thought I would write a post on it in the spirit of the rest of the world learning from my mistakes ;) . The project (that I cant tell you about yet) required a bunch of songs represented by their spectral-waveforms. I tried to find an application that would generate them for me easily but I couldnt really find a simple one. There are some applications that do it but they have so many controls that I couldnt figure out how to do it really quick. I still had source code from my FlexAmp application lying around so I figured, what the heck, I'll just write a small application to do it. The result was the SpectrumGrapher application.

The concept is pretty simple:
1) Browse to a song on your filesystem.
2) Select it and it begins playing as well as using the computeSpectrum method to draw the graph (using a function that uses the drawing api thats called by a timer)
3) Click on the 'Snapshot' button to take a snapshot of the drawing (using the bitmap information of the UIComponent and the Bitmap to png class in the Adobe corelib)
4) Write the png file to the filesystem with a name like [song]_waveform.png

Screen shots (click for larger image)

Choose File
Choose File


Drawing Spectrum

Drawing the Spectrum

Final Waveform png
The output waveform (as saved to the desktop)

The problem I faced was after about 6-10 seconds of playback, my cpu would start spiking since I had too many vectors on the stage. The solution was a modified version of Grant Skinner's 'copy vector into bitmap and clear the vector' approach. I put another timer that fired an event every 5 seconds to do that. The result: I tried a song that lasted almost 8 minutes and no issues (yeah Dream Theater songs are loooooong...but cool ;) ). The other thing I just discovered was that using a filetype filter to control enabling/disabling the select button on the browse window doesnt seem to work on the mac ( I am a mac newbie and did this development on my PC). The more interesting output of this project was the file chooser dialog box which I had to write since the apollo alpha release doesnt give access to the native file chooser control (although I have seen it on the beta build demo). Maybe I'll release that part of the code sometime soon.

Let me know what you think :)

Talking Flex with the Philadelphia Flash Platform Adobe User Group 1

Comcast Interactive Media (CIM) is hosting the next PFPAUG meetup and I will be talking on how we use Flex here in applications that immediately appear in front of millions of people. My recent blog entry on how we used Flex to develop the next version of the square view of the Fan got quite a bit of attention in the blogosphere and I think we did a fairly good job of developing a Flex application the way adobe has envisioned. I am thinking this will be a mid to advanced level talk on Flex and we will cover things like skinning, debugging and our build system using Ant. If you are in or around Philadelphia around May 31st, come on down to 1500 Market Street. There will be food and we will also be giving away some goodies.

If anyone has anything they would specifically like to be covered, drop me a comment below and I will try to include that in the talk. More details on the event can be found at the PFPAUG page.

New top reason to work at CIM: See Spiderman 3 before it opens ;) 1

Woohoo. We (the entire Comcast Interactive Media group) just got back from a private screening of the new Spiderman movie. The whole theater was rented out for us and food and soda were aplenty.

We are still looking for developers across the board, so if you have coding skill in any domain, c'mon over.

Mail me at mathur.arpit [at] gmail dot com