I faced a trouble when i work with XML. It's teach me a lot. From that gathered info, i shared my thoughts.
First of all, we have to understand the XML and XMLlist. XML is well-formed structure of information. And we created the XML using XML class in as3.
XMLList is the collection of XML objects. We can collect the XML values use descent operator.
The main difference is XML has a single root and XMLList have multiple roots because it's a collection of XML objects.
For an Example:
var xml:XML = new XML(
<menu>
<item id="">
<screen>
<screen1>Value 1 </screen1>
<screen2>Value 2 </screen2>
</screen>
<screen>
<screen3>Value 3 </screen3>
</screen>
</item>
</menu>);
You can traverse xml using descent operator(.) and Screen value in array-collection.
var xmlList:XMLList = xml.item.screen;
var valusAr:ArrayCollection = new ArrayCollection();
var tagnamesAr:ArrayCollection = new ArrayCollection();
for each(var item:XML in xmlList.children()){
valusAr.addItem(item.text());
tagnamesAr.addItem(item.localName());
}
The result will be
valuesAr :Value 1, Value 2, Value 3
tagnamesAr: screen1, screen2, screen3
Finally, XMLListCollection is nothing like arrayCollection class because the two class extends ListCollectionView class.
Using this we may use sort, filter properties for XMLList collection object.
Flex Thoughts
This blog is about flex. From my experience, I shared my thoughts........
Thursday, December 6, 2012
Monday, August 27, 2012
Export Special Characters to Excel
In this post, i share while we export our datagrid values to excel which includes special characters.
You may using as3xls library file, to include that but main drawback is you couldnt add more than 256 characters into the excel cell. Because, we coulnt use writeMultiBytes() over there. Its not working properly to me.
So, i convert all to CSV format. If u want to insert Some special characters like pound(£), dollor($) etc, have to use writeMultibytes().
Example:
var finalCSVString:String; // csvLine holds all values as String.
var csvBytes:ByteArray = new ByteArray();
csvBytes.writeMultiByte(finalCSVString, "utf-16");
var csvFile:FileReference = new FileReference();
csvFile.save(csvBytes,"Export.csv");
Converting & Understanding CSV format:
The Comma-Seperated Values format, its copy the strings in to cell by comma. So Each values should converted as string. The below example shows how to we insert string into correspond cell.
var headLine:String;
var empName:String = "Yamuna"; //Values may cahnge dynamicaaly
var sal:String = "£1000";
headLine = "\"Employee Name\"";
headLine += ",\"" + empName +"\"\n";
headLine = "\"Salary\"";
headLine += ",\"" + sal +"\"\n";
headLine += "\"End Here"";
",\"" - It is used to add comma between string to insert strings into two consecutive cells.
Now headLine looks like
"Employee Name","Yamuna"
"Salary","£1000"
"Ends Here"
So i Excel Sheet
A1 A2
1 Employee Name Yamuna
2 Salary £1000
3 Ends Here
You may using as3xls library file, to include that but main drawback is you couldnt add more than 256 characters into the excel cell. Because, we coulnt use writeMultiBytes() over there. Its not working properly to me.
So, i convert all to CSV format. If u want to insert Some special characters like pound(£), dollor($) etc, have to use writeMultibytes().
Example:
var finalCSVString:String; // csvLine holds all values as String.
var csvBytes:ByteArray = new ByteArray();
csvBytes.writeMultiByte(finalCSVString, "utf-16");
var csvFile:FileReference = new FileReference();
csvFile.save(csvBytes,"Export.csv");
Converting & Understanding CSV format:
The Comma-Seperated Values format, its copy the strings in to cell by comma. So Each values should converted as string. The below example shows how to we insert string into correspond cell.
var headLine:String;
var empName:String = "Yamuna"; //Values may cahnge dynamicaaly
var sal:String = "£1000";
headLine = "\"Employee Name\"";
headLine += ",\"" + empName +"\"\n";
headLine = "\"Salary\"";
headLine += ",\"" + sal +"\"\n";
headLine += "\"End Here"";
",\"" - It is used to add comma between string to insert strings into two consecutive cells.
Now headLine looks like
"Employee Name","Yamuna"
"Salary","£1000"
"Ends Here"
So i Excel Sheet
A1 A2
1 Employee Name Yamuna
2 Salary £1000
3 Ends Here
Wednesday, May 16, 2012
Custom Currency Format using as3
Here I'm going to share about Currency Formatter class in Action Script 3.
Using this, we may change currency format in flex. By default, This class return an string "-$100", for the Input "-100". But, while we undoing this, we only get "100"(It excludes negative sign which before Currency Symbol, whatever it may be) . This is because, Currency formatter doest mind any symbol before currency symbol. Even though, we using "useNegativeSign" property as true.
In default, the class first assign sign,then symbol, then number.In base class, i.e, in CurrencyFormatter.as class is as follows:
if (alignSymbol == "left")
{
if (isNegative)
{
var nSign:String = numStr.charAt(0);
var baseVal:String = numStr.substr(1, numStr.length - 1);
numStr = nSign + currencySymbol + baseVal;
}
else
{
numStr = ncurrencySymbol + numStr;
}
}
}
Remedy is, we have to create Custom class for CurrencyFormatter. We have to override a format() function.
We just change that format to our needs, like first symbol and followed by sign, then numbers.
if (super.alignSymbol == "left")
{
if (isNegative)
{
var nSign:String = numStr.charAt(0);
var baseVal:String = numStr.substr(1, numStr.length - 1);
numStr = super.currencySymbol + nSign + baseVal;
}
else
{
numStr = super.currencySymbol + numStr;
}
}
}
After this, we may create an instance for our custom Currency class in usual way. And assign properties whatever we need. Say an example, I'm creating custom class instance for my CustomCurrency Format class.
var m:MyCurrencyFormat = new MyCurrencyFormat();
m.precision = 2;
m.useThousandsSeparator = true;
m.currencySymbol = "£";
result.text = m.format(txtInput.text);
Hope, May this post help somebody!!!
Using this, we may change currency format in flex. By default, This class return an string "-$100", for the Input "-100". But, while we undoing this, we only get "100"(It excludes negative sign which before Currency Symbol, whatever it may be) . This is because, Currency formatter doest mind any symbol before currency symbol. Even though, we using "useNegativeSign" property as true.
In default, the class first assign sign,then symbol, then number.In base class, i.e, in CurrencyFormatter.as class is as follows:
if (alignSymbol == "left")
{
if (isNegative)
{
var nSign:String = numStr.charAt(0);
var baseVal:String = numStr.substr(1, numStr.length - 1);
numStr = nSign + currencySymbol + baseVal;
}
else
{
numStr = ncurrencySymbol + numStr;
}
}
}
Remedy is, we have to create Custom class for CurrencyFormatter. We have to override a format() function.
We just change that format to our needs, like first symbol and followed by sign, then numbers.
if (super.alignSymbol == "left")
{
if (isNegative)
{
var nSign:String = numStr.charAt(0);
var baseVal:String = numStr.substr(1, numStr.length - 1);
numStr = super.currencySymbol + nSign + baseVal;
}
else
{
numStr = super.currencySymbol + numStr;
}
}
}
After this, we may create an instance for our custom Currency class in usual way. And assign properties whatever we need. Say an example, I'm creating custom class instance for my CustomCurrency Format class.
var m:MyCurrencyFormat = new MyCurrencyFormat();
m.precision = 2;
m.useThousandsSeparator = true;
m.currencySymbol = "£";
result.text = m.format(txtInput.text);
![]() |
Hope, May this post help somebody!!!
Tuesday, March 27, 2012
RSS Feed
What is RSS?
RSS is a technology that is being used by millions of web users around the world to keep track of their favorite websites.
In the ‘old days’ of the web to keep track of updates on a website you had to ‘bookmark’ websites in your browser and manually return to them on a regular basis to see what had been added.
The problems with bookmarking
- You as the web surfer had to do all the work
- It can get complicated when you are trying to track many websites at once
- You miss information when you forget to check your bookmarks
- You end up seeing the same information over and over again on sites that don’t update very often
RSS Changes Everything
What if you could tell a website to let you know every time that they update? In a sense, this is what RSS does for you.
RSS flips things around a little and is a technology that provides you with a method of getting relevant and up to date information sent to you for you to read in your own time. It saves you time and helps you to get the information you want quickly after it was published.
RSS stands for ‘Really Simple Syndication’. Many people describe it as a ‘news feed’ that you subscribe to.
I find the ‘subscription’ description helpful. It’s like subscribing to a magazine that is delivered to you periodically but instead of it coming in your physical mail box each month when the magazine is published it is delivered to your ‘RSS Reader’ every time your favorite website updates.
How RSS actually technically works is probably a lesson for another day but the key today is for you to understand why it’s good and how to use it.
Let me say right up front that I’m not the most technically savvy guy going around – but even I can use RSS. At first I found it a little strange to make the change from bookmarking to RSS but I found that when I started that I just couldn’t stop.
How to Use RSS
Get an RSS Reader – The first thing you’ll want to do if you’re getting into reading sites via RSS is to hook yourself up with an RSS Feed Reader.
There are many feed readers going around with a variety of approaches and features – however a good place to start is with a couple of free and easy to use web based ones like Google Reader andBloglines. Either one will do if you’re starting out (I use Google’s Reader) – as I say there are many others to choose from but to get started either of these are fairly easy to use and will help you work out the basics of RSS.
Both of these feed readers work a little like email. As you subscribe to feeds you’ll see that unread entries from the sites you’re tracking will be marked as bold. As you click on them you’ll see the latest update and can read it right there in the feed reader. You are given the option to click through to the actual site or move onto the next unread item – marking the last one as ‘read’.
The best way to learn how to use either Google Reader or Bloglines is to simply subscribe to some feeds and give it a go. Both have helpful help sections to get you up and running.
Note: other options to tracking websites that you might already be familiar with include using pages like MyYahoo, MyGoogle and MyMSN.
Subscribe to:
Posts (Atom)
