Archive for June, 2007

XML 101 in AS3/E4X: Take #1

June 29, 2007

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

public class TestXML01 extends Sprite
private var foo:TextField;
private var rssURI:String = “”;
//private var
public function TestXML01()
private function init():void
foo = new TextField();
foo.autoSize = TextFieldAutoSize.LEFT;
foo.width = 600;
//multiline should be true in order to use <br> tags
foo.multiline = true;
foo.wordWrap = true;
foo.htmlText = “loading feed…”;
private function loadXML():void
var urlRequest:URLRequest = new URLRequest(rssURI);
var urlLoader:URLLoader = new URLLoader();

//xml should be, and defaults to type of URLLoaderDataFormat.TEXT;
//trace(“urlLoader.dataFormat: “+urlLoader.dataFormat);
//urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
//Event “complete” is flash.Event.COMPLETE
urlLoader.addEventListener(Event.COMPLETE, onXML);

//There are a whole bunch of other events to handle, among them are (event types):

private function onXML(evt:Event):void
//onXML should try to handle errors at the meantime
//xml object gets returned as a property named “data” of the corresponding urlloader object
//Note we first need to cast it to type of XML first. Then xml becomes the top node of the returned xml document, which in this case is the <rss>…</rss> node, which contains the <channel> node:

var xml:XML = new XML(;
foo.htmlText = “<b>”+e.message+”</b>”;
private function handleXML(xml:XML):void

//XML.ignoreWhitespace = true;
var str:String = “”;
str += “<b>””</b><br>”;
str +=”<i>””</i><br><br>”;

//use toXMLString() to inspect a node

//both XML and XMLList are top level objects

//get the list values of children
var itemList:XMLList =;
//length() is a method of XMLList object
var totalItems:uint = itemList.length();

str +=”<ul>”;

for(var i:uint = 0; i<totalItems; i++)
var title:XML = itemList.title[i];
var link:XML =[i];
str +=”<li><a href='”+link+”‘ target=’_news’>”+title+”</a>”;

str +=”</ul>”;
foo.htmlText = str;
//manually destroy str
//str = null;


convert string into date

June 23, 2007

I wanted to convert a column whose data type of string into that of date.

First add a column with data type of date;


UPDATE `myTable` SET `REALDATE`= str_to_date( `SRTDATE` , '%m/%d/%Y' );

This will convert ’06/23/2007′ in STRDATE into ‘2007-06-23’ in REALDATE.