Dec 29

If you have an ArrayCollection and need to sort it, heres a quick example:

import mx.collections.ISort;
import mx.collections.ISortField;

var sort:ISort = new Sort();
var sortfieldNome:ISortField = new SortField(”name”,true); // “name” is a field on the arraycollection
var sortfieldEmail:ISortField = new SortField(”email”,true); // “email” is another field on the arraycollection
sort.fields = [sortfieldNome, sortfieldEmail];
myArrayCollection.sort = sort;

// this next line is used if you want the sort to be reversed.

// sort.reverse();

// Apply the sort to the collection.
myArrayCollection.refresh();

References:

from Adobe Help - spark.collections.sort - read it. its a good source of information


Dec 29

On my day job, i needed to copy an ArrayCollection to a different var so i could manipulate it without affecting the original. Went with this:

arraycollection2 = arraycollection1;

With this method, all i did to arraycollection2 was also happening to arraycollection1.

to copy arrayCollection1 to arrayCollection2 without making it a reference:

arrayCollection2 = ObjectUtil.copy(arrayCollection1) as ArrayCollection;

That’s that.

Oh, and make sure you import this:

import mx.utils.ObjectUtil;


Dec 8

Spending a lot of time in front of my monitor looking at code on a white background was slowly getting on my nerves. I looked up on changing the flash builder IDE color scheme and came up with some nice alternatives. My life coding life just got much nicer…and darker.

This is tested on Flash Builder 4.5/4.5.1/4.6:

1. Go to menu Help -> Eclipse Marketplace…;

2. Search for “theme”;

3. Find the entry called “Eclipse color theme” and install;

4. Go to menu Window -> Preferences;

5. Go to entry General -> Appearance -> Color Theme;

6. Select your favorite theme;

7. Write back and thank me for saving your eyes from the white coding death.

Optional - to change specific colors like background, selections, etc.:

In Window -> Preferences:

- General -> Appearance -> Colors and Fonts

- General -> Editors -> Text Editors

- General -> Editors -> Structured Text Editors

- Flash Builder - Editors - Syntax Coloring

I use an altered zenburn theme.


Oct 15

This is a recurring problem i had. For some reason (which i later found out), i couldnt get my php scripts to connect to postgresql. The scripts borked at, for example, pg_connect() (unable to find the function, blah blah).

First off, usually php doesnt come configured to run the postgresql dll out of the box (the windows extension is commented), so you have to uncomment it yourselves.

In php.ini, uncomment (remove the “;”) the following line:

;extension=php_pgsql.dll

so it becomes

extension=php_pgsql.dll

Still, when i restarted Apache, i got the error:

Unable to load dynamic library ‘c:\Programs\PHP\ext\php_pgsql.dll’”

Which was intriguing since the dll was where it was supposed to be.

As it turns out, on later versions of php, the dll is linked to “libpq.dll”, a postgresql dll. So, to fix things, i added the following line to httpd.conf:

LoadFile “C:/Programs/PostgreSQL/9.0/bin/libpq.dll”

(replace the path to your postgresql installation dir, of course - and be careful copying the line above because of the “)

this way the dll is preloaded when apache is started and we dont get the “Unable to link…” error.

This was tested with xampp on windows xp pro, with apache 2.2.17, php 5.3.5 and postgresql 9.0. Other versions can probably affect the solution presented.

PS - On some situations (probably php versions), it is needed to replace the php_pgsql.dll file that comes with php with one from a previous version. This wasnt necessary on my case.

Heres a useful link from where i got the info:

http://php.net/manual/pt_BR/install.windows.apache2.php (see the comments)

UPDATE:

Ran into the same problem, but this time on windows 7 64bit. I was using XAMPP 1.7.7 (Apache 2.2.21 / PHP 5.3.8) and postgresql 9.1 64bit.

- I uncommented the php_pgsql.dll in php.ini, restarted apache and got an error.

- Added the loadfile line (see above) to httpd.conf and the apache service couldnt start.

No matter what i did, nothing worked. After a few hours of head banging, i had the bright idea of searching for the 64bit part on the postgresql install and i found this article:

http://blog.hagander.net/archives/73-PostgreSQL-vs-64-bit-windows.html

(in case you dont want to read, it says, in a nutshell: you are safe using the 32bit version of postgresql on a 64bit OS)

So i thought the problem might be from just that. Heres what i did:

- Installed the 32bit version of postgresql 9.1

- Added the loadfile line to httpd.conf.

- Restarted the apache service…and it worked.

So we end up with: Windows 7 Ultimate 64bit + XAMPP 1.7.7 + PostgreSQL 9.1 32bit + Smile


May 25

To add a line break inside the text of a TextArea component in flex we cannot use \n, but instead use ‘
’ (without the quotes).

For example:

<s:TextArea text=”this text will be on the first line&#13;and this one on the second” …/>

will produce a text box with this text:

this text will be on the first line

and this one on the second


May 18

To create a thumbnail to go along with the image you upload to the DB using PHPMaker, you do something like this:

For the sake of simplicity, let’s assume you have two directories:

- “imgs_sessoes” - for all the regular size images

- “imgs_sessoes_tn” - for the thumbnails

After configuring PHPMaker to upload, and resize if you want, the images, you go to Server Events/Client Scripts, item Row_Inserting and add:
function Row_Inserting(&$rs) {
$file=$rs['ficheiro'];
$this->ficheiro->Upload->ResizeAndSaveToFile(100, 100, 80, “imgs_sessoes_tn/”, $file, TRUE);
return TRUE;
}

Change your image field as appropriate (mine is called “ficheiro”)

NOTE - ResizeAndSaveToFile() takes 6 arguments: width, height, quality, directory, filename, and boolean for overwrite.

To delete thumbnaill along with regular image, ad in Row_Deleting:

function Row_Deleting(&$rs) {
$filename=$rs['ficheiro'];
@unlink(”imgs_sessoes_tn/”.$filename);
return TRUE;
}

NOTE - Again, notice the name of the field.


Mar 29

Yes, i know, very very easy. But i am leaving this here as reference:

$texto = “how to count words in a very simple step”;

$contagem = preg_match_all(”/\w+/”, $texto, $blaharray);
echo $contagem; // 9

For further reading:

Regular Expressions info

preg_match()

preg_match_all()


Mar 14

Just to settle this once and for all:

include(’file.php’); // will include file.php and emite a WARNING if the file is not found

require(’file.php’); // will include file.php and emit a FATAL ERROR if the file is not found

require_once(’file.php’); // PHP will check if the file has already been included, and if so, not include (require) it again.

include_once(’file.php’); // same as require_once, but will evaluate the file before (yes, its include, with warning and checks to see if file exists).

So there you have it, kids. Just so you(*i*) never forget.


Mar 9

This is a fix for a recurring problem. When we want to make the datagrid’s height to cover its content (dataprovider).

<mx:DataGrid xmlns:mx=”http://www.adobe.com/2006/mxml”
variableRowHeight=”true” verticalScrollPolicy=”off” wordWrap=”true” rowCount=”{dataProvider.length}”
dataChange=”resize()” columnStretch=”resize()” resize=”resize()” >

<mx:Script>
<![CDATA[

//This is a work around for the poorly designed wordWrap and variableRowHeight features of the DataGrid
private function resize():void
{
if (dataProvider)
{
var h:Number = measureHeightOfItems( -1, dataProvider.length + 1);
if (h > maxHeight && maxHeight != 0)
{
verticalScrollPolicy = "on";
h = maxHeight;
}else{
verticalScrollPolicy = "off";
this.height = h;
}
}

]]>
</mx:Script>
</mx:DataGrid>

Got it from here:

<a href=”http://www.actionscript.org/forums/showthread.php3?t=220962″ target=”_blank” >http://www.actionscript.org/forums/showthread.php3?t=220962</a>


Feb 16

Following the update with data from another table, i am leaving this for quick reference.

To insert data into table2 from table2:

insert into table2 (field1,field2,field3)
select table1.field1,table1.field2,table1.field3 from table1

(all the above is on the same line)

We can make this as complex as needed.