Archive for January, 2008

TortoiseSVN (UI client) cheat sheet

January 6, 2008
  • Starting a new project
  1. Create a new repository at server side. E.g., myserver.com/codesnippets;
  2. At the client side set up an empty folder with all the necessary structures inside it. E.g., codesnippets/trunk. Right click the folder->TortoiseSVN->Import to get the empty folders up to the destination repository;
  3. Once the structure is ready at the repository, select the folder of contents you need to import to the repository and import the content to the destination repository;
  4. Now with the repository set up at the SVN server, we would need to keep a working copy at the client side to keep version control in synchronization. We do this by “checking out” from the repository. To do this, create a clean folder (or select a folder that has no previous SVN checkout history) and right click->SVN Checkout and specify myserver.com/codesnippets as the URL of the repository. This downloads the contents inside the repository to the folder.
  • Sending Your Changes To The Repository
  1. Use TortoiseSVN → Update or TortoiseSVN → Check for Modifications to see if there are any conflicts first;
  2. If there are no conflicts and your working copy is up to date, select any file and/or folders you want to commit, then TortoiseSVN → Commit…;
  3. If you need to rename, delete or move a file, use the SVN dialog menu to make the changes as to keep SVN aware of them. (TortoiseSVN is capable of detecting drag-drop to the files within a working copy of a repository.) Then repeat step 1, 2 to commit your changes to the repository.
  • Updating Your Working Copy With Changes From Others/The Repository
  1. The process of getting changes from the server to your local copy is known as updating. To update, select the files and/or directories you want, right click and select TortoiseSVN → Update in the explorer context menu.

E4X in ActionScript 3 and Flex 3

January 1, 2008

The following top AS3 classes, in conjunction with HTTPService and mx.rpc.events.ResultEvent classes are used in Flex (2+) to handle XML:

XML/XMLList/Namespace/QName

XMLList Class can be considered a collection of XML objects. It is a native ActionScript class that is advised to handle XML such as data binding. XMLNode has become the legacy class in AS 2.

So the first step of handling XML data is to deserialize an XML document or object into XMLList objects.

<mx:HTTPService id="dataFetcher" url="http://mysite/myData.xml" resultFormat="e4x" result="onData(event)" />

Remember you will almost always need to initialize the call by adding the following code to the “creationComplete” event handler of the mx:Application node:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="dataFetcher.send()"/>

To deserialize the an XML object (sample shown as follows), use ResultEvent Class, like so:

<delSum Test="1" timestamp="2007-12-10T21:07:48Z">
<del pId="Dem" dNeed="2029" dTot="4056" dChosen="991" dToBeChosen="3237">
<Cand cId="1746" cName="Clinton" dTot="290" d1="+290" d7="+290" d30="+150"/>
<Cand cId="1918" cName="Obama" dTot="194" d1="+194" d7="+194" d30="+55"/>
</del>
<del pId="GOP" dNeed="1113" dTot="2225" dChosen="251" dToBeChosen="2153">
<Cand cId="893" cName="Romney" dTot="109" d1="+109" d7="+109" d30="+1"/>
<Cand cId="302" cName="Paul" dTot="47" d1="+47" d7="+47" d30="0"/>
</del>
</delSum>

private function onData(event:ResultEvent):void
{
demData = event.result.del.(@pId=="Dem").Cand.(@cName!="Uncommitted");
gopData = event.result.del.(@pId=="GOP").Cand.(@cName!="Uncommitted");
}

Note that event.result represents the top node, which is <delSum> node in the XML document.

XML filtering:

To locate a set of XML objects that represents similar characteristics, use the parenthesis () to include sets of boolean statements, following a dot after the node you want to carry out the filtering against, like so:

var product1:XMLList = catalog.product.(@id==1);//Returning the product node or nodes if there are multiple products whose id is equal to 1

or

var productName:String = catalog.product.(price<50).name;//Returns the name node

or

var manufName:String = catalog.product.(price<50).@manufacturer;//Returns the manufacturer attribute under the name node

To get list of candidate names:

var _tst:XMLList = event.result.del.(@pId=="GOP").Cand.(@cName!="Uncommitted").@cName
trace((_tst[0] is XML)+"; "+_tst[0].nodeKind() )//Returns "true; attribute"
trace(gopData[0].@cName+"; "+(gopData[0].nodeKind())//Returns "Romney; element"

Types of node include: text, comment, processing-instruction, attribute, or element.