Tips & Tricks

Filter an ArrayCollection and don’t lose the original data

by Alberto González on May.02, 2009, under ActionScript, Adobe AIR, Adobe Flex, Coding, Tips & Tricks

Yesterday, one of my students asked me about recovering the original data of an ArrayCollection if this ArrayCollection has a filter applied.In Adobe Flex, the ArrayCollection class has a property called filterFunction. We can assign a function reference directly to this property and then apply a refresh() to the ArrayCollection instance.This is an example.

// Defining the ArrayCollection instanceprivate var ac:ArrayCollection = new ArrayCollection([{label:"Adobe Flex", data:"Fx"},{label:"Adobe Flash", data:"Fl"},{label:"Adobe After Effects", data:"Ae"},{label:"Adobe Flash Player", data:"fp"}]);//Defining the filter functionprivate function flashFilter(obj:Object):Boolean{return obj.label.toLowerCase().indexOf("flash") != -1;}//Applying the filterac.filterFunction = flashFilter;ac.refresh();

Once the filter is applied, the ArrayCollection hides all the objects that don’t pass the validation in the function and shows the objects that do.
An ArrayCollection stores internally an instance of the Array class. You can see that in the previous example where I place an array inside the constructor of the ArrayCollection.
An ArrayCollection acts as a “wrapper” for the array instance enabling functionality that belongs to collections and lists. This functionality can be, filtering, sorting, add/remove/modify data and more.
After you filter an ArrayCollection instance the “wrapper” only shows the unhidden objects and it seems like it only has 2 elements (in my example), I mean if you test the “length” property after the filter you will see that it shows the value 2. But we know the truth, the ArrayCollection actually has 4 elements. If you want to get back this 4 elements without clearing the filter you have to deep into the ArrayCollection and find the source. This source, as I said previously, is an Array.
You will find the source using, in fact, the “source” property of the ArrayCollection. The array that will give you this property is the complete set of data that the ArrayCollection is storing without any filter. Just don’t forget that “source” is giving you an instance of an Array and not an instance of an ArrayCollection.

//continuing the previous example...//Applying the filterac.filterFunction = flashFilter;ac.refresh();//Test the length property of the ArrayCollectiontrace(ac.length); // 2//Test the source property of the ArrayCollectiontrace(ac.source) // [object Object],[object Object],[object Object],[object Object]//Test the length property of the source propertytrace(ac.source.length) // 4
6 Comments :, , more...

Juice, a new excellent firefox extension

by Alberto González on Nov.04, 2008, under General, New Releases, Tips & Tricks

Today I downloaded this new extension for firefox called Juice.
If you’re one of the people who loves being informed and to know about everything, or almost everything, I can tell you that you need this extension.
Juice allows you to watch news, videos, images, blogs and everything in just one sidebar divided by tabs and buttons. You just have to drag any text from the main browser window to anywhere in the browser and Juice will try to find everything about that text.
You can also save your images and bookmark your favorite videos in Juice.
You should take a look at this new extension.
Best.

Leave a Comment :, more...

Profiling Flash Applications with Flex Builder 3

by Alberto González on Aug.03, 2008, under Adobe Flash, Adobe Flex, Tips & Tricks

If you use to create Flex Apps I’m almost sure you profile your applications with Flex Builder or with another tool related to. This time I’ll talk about profiling applications.
Profiling an application means to inspect the elements that your application is running, how much memory you application is consuming, how many instances of each class your application is executing and more information. You can compare memory snapshots of the same application but in different execution time, etc.
You can profile with Flex Builder any application generated as swf file, this includes Flex Applications, Flash Applications/Web sites/animations and any swf created with any tool that has the capability to export the project as swf file.
Before you profile an application you must ensure that the swf file has been compiled with debugging capabilities. Flex does this job for you every time you run, debug or profile your application from Flex Builder, but in Flash this doesn’t happen. You must explicitly tell Flash that your swf must be compiled for debugging. You can do this from the publish settings panel. In the flash tab you have a checkbox unselected by default which says “Permit debugging” and you must turn it on.
Flash debug option
When you turn on this option your application will be compiled with the compiler argument “debug=true”. (You can also compile your application directly with that compile argument if you have a Flash Compiler). The compiler will embed to the swf file information needed for debugging the application, also it will try to connect the application by socket to a socket server when it starts. Flex Builder starts up that socket server when you profile or debug a swf file from Flex Builder with the green buttons in the toolbar, so, as you can imagine, you should first start up the server and then execute the swf file.
From Flex builder you have to profile an external application. You will find this option in the Menu bar – Profile – Profile External Application. This will launch a pop up window that will ask you for the swf file of the application you want to profile. You also have the option to just prepare Flex Builder for profiling and let it wait for the application to execute and connect to Flex Builder (for this you have to choose “Launch the application manually outside Flex Builder”). I will emphasize the first option which profiles directly the selected application. In this window you can browse for the swf file compiled previously in Flash or Flex with the debug option and then you just launch the profiling process and that’s all.
Flex Profile External Option
Select swf file
Don’t forget to turn off the “Permit debug” option from Flash or clear the “debug” compile argument in production mode because someone could debug you application remotely from his computer.
Enjoy it.

5 Comments :, , , more...

ActionScript 3.0 tips, tricks and how tos…

by Alberto González on Aug.02, 2008, under ActionScript, Coding, Tips & Tricks

Today I decided to make some posts about tips, tricks and how to do some useful things in ActionScript 3.0 for Flash CS3 and Flex 3, also for LiveCycle Data Services with Java and PHP.
This happened because I’ve been receiving some technical questions about ActionScript 3.0 in general and Flex integration with other technologies. After that, a friend of mine told me that It’ll be useful that I post those answers and some tips/tricks in my blog.
I’ll try to post once a day about this topics but I can’t promise that I will. So lets start…
I will start with one of the first things I realized that it is more difficult to do than in past versions of ActionScript. This is the generation of class instances when the class name is dynamically generated.
I will create an sample environment.Imagine that you have an application where the graphic elements in this app are created based on user decisions. This example is very common, but… What you really have to do is to create instances of a Class that, at the moment of the application initialization, you still don’t know.
Lets see…You have three classes

BlueButtonOrangeButtonGreenButton

You dont know what type of class instance will be created so you just let it to be dynamically generated. You can do this with a method inside “flash.utils” package named getDefinitionByName.
getDefinitionByName takes a string argument and try to get the whole class reference, so you could create a new instance based on this new class reference.

import flash.utils.getDefinitionByName;var ClassReference:Class = getDefinitionByName("BlueButton") as Class;var newInstance:* = new ClassReference();

You could have the “BlueButton” string inside a variable.Because at compile time you still don’t know what data type will have the “newInstance” variable, I recommend not to specify it yet. You could then get the class name and cast the variable to the correct datatype.
You can get the class name with another function inside the same package. The function name is “getQualifiedClassName”. You can pass an instance reference as the only argument and the function will give you a string with the name of the class that the instance belongs to.
Also, there is another function named “getQualifiedSuperclassName” which acts almost the same as getQualifiedClassName. The only difference is that this function gives you the name of the super class instead of the class.

import flash.utils.getQualifiedClassName;import flash.utils.getQualifiedSuperclassName;trace(getQualifiedClassName(newInstance)); // BlueButtontrace(getQualifiedSuperclassName(newInstance)); // SimpleButton

This is an example. The source code is in the “files” section of this blog.Hope you find it usefull.
Regards

3 Comments more...

My firefox extensions

by Alberto González on Jun.24, 2008, under General, Tips & Tricks

With this new release of Firefox 3 I’d like to post my favorite firefox extensions. Extensions that I use every day when I surf the Internet, in a developing process, when I talk by instant messengers, and more.
Here is the list.

  • Web Developer Toolbar (Obviously). For people who still don’t know Web Developer Toolbar I can tell you that you can explore so much stuff related to the current page you’re viewing in the browser. You can clear private data, show div order, enable/disable CSS, JavaScript, Java, Cache, resize the browser and more, and every one of them can be manipulated in a very easy way.
  • measureIt. This extension allows me to measure any region of the web page in a very ease way and at “runtime”. I mean, while you’re watching the pretty sidebar of a web page you can measure it and this tools can give you the pixels.
  • UrlParams. This extension allows me to view and modify every one of the parameters that are sent to the current web page I’m actually viewing in the browser. Every one of the “get” and “post” parameters. So now, you can see and modify those POST variables you didn’t event know were sent to the web page.
  • Better Gmail. As many of, you I also work with Google Mail and if that wasn’t enough I have three e-mail accounts hosted in Google using Google Applications for your domain, for having the same user interface in my private domains as in gmail. Better Gmail gives you more options and settings when you use gmail. Some of them can be very very useful. I do recommend this extension If you work with gmail every day.
  • del.icio.us buttons. This extension allows you to tag very quickly a web page to your del.icio.us account. You don’t need to open a del.icio.us page you just click on a button and that’s all, the web page will be tagged. Also you can go to your delicious account with one click.
  • Facebook toolbar. I’m sure many of you have a facebook account. This extension place an horizontal toolbar in firefox. From this, you can log in into your facebook account, go to your photos, friends, profile and more with a single click, this toolbar show a little popup when any of your friends has updated profile, or status, you can search in facebook and more.
  • Download status bar. “You’re not going to download a status bar”. This is a toolbar that is placed where the status bar is. Don’t you hate when you’re going to download something and a pop up window jumps right in front of you with all your firefox downloads ? I do. and when I found this extension I really loved it. This is done just for having a minimal view of the downloads and their progress. Once opened from the toolbar you wont see them again in firefox, just in the folder they are.
  • Well, these were my favorite firefox extensions. Do you have more you think are useful ??? Well, post a comment about them.

    ;-)

    2 Comments :, , , , , more...

    Looking for something?

    Use the form below to search the site:

    Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!