<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-674134548655639627</id><updated>2011-07-30T18:49:41.024-07:00</updated><category term='Programming Style'/><category term='RIA Flash Actionscript'/><category term='Flash'/><category term='Flash Player 10'/><category term='RIA Flex Flash Actionscript SWF'/><category term='Tree'/><category term='Astro'/><category term='ActionScript'/><category term='Flex'/><category term='XML'/><category term='E4X'/><category term='JavaScript'/><category term='SWF'/><title type='text'>FreerPad</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-2574608864519046300</id><published>2008-07-04T06:00:00.001-07:00</published><updated>2008-07-04T06:04:51.549-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SWF'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash Player 10'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash'/><category scheme='http://www.blogger.com/atom/ns#' term='Astro'/><title type='text'>Flash Player: Text Around A Circle</title><content type='html'>&lt;p&gt;I received a rare and &lt;strong&gt;very welcome &lt;/strong&gt;comment about my most recent postings about the new Flash Player 10 (FP10) and my 1st demo, &lt;a href="http://freerpad.blogspot.com/2008/06/flash-10-beta-development-without.html"&gt;FontWheels&lt;/a&gt;.&amp;#160; In his comment, OLMSTJ, mentioned he was currently working on a project where he was placing text around a circle and therefore curious how I approached doing it in my demo.&lt;/p&gt;  &lt;p&gt;Unlike my previous published code, for example my sort function for XML, this code is not at the point where it is generic.&amp;#160; It was actually more generic when I first built it for Flash Player 9 (FP9) when I was rotating text first converted to bitmaps.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://www.elegantfloraldesigns.us/blogstuff/TextOnACircleFP9/TextOnACircleFP9.html" target="_blank"&gt;&lt;img style="margin: 0px 5px 0px 0px" src="http://www.elegantfloraldesigns.us/blogstuff/FontWheels/TextOnACircleFP9.jpg" align="left" /&gt;&lt;/a&gt;So I’m going to release the &lt;a href="http://www.elegantfloraldesigns.us/blogstuff/TextOnACircleFP9/TextOnACircleFP9.as.txt" target="_blank"&gt;FP9 code&lt;/a&gt;, a single static function wrapped in a simple &lt;a href="http://www.elegantfloraldesigns.us/blogstuff/TextOnACircleFP9/TextOnACircleFP9.html" target="_blank"&gt;demo&lt;/a&gt;.&amp;#160; The framework (oh, I hate that word) for the old and new functions are similar but there are differences in how I place each character.&amp;#160; If at some point, I reduce the FP10 code to a similar scope, I’ll probably publish that code.&amp;#160; The FP10 code has a lot more functionality due to the demo’s requirement to stuff an entire circle with different font fields and other minor details that wouldn’t be needed outside the demo.&lt;/p&gt;  &lt;p&gt;I did stripped a little code from the FP9 function.&amp;#160; It converted the complex Sprite to a single centered bitmap in a Sprite.&amp;#160; Each text character is implemented with a Bitmap inside its own Sprite.&amp;#160; Since I tend to make my pages very detailed, I like to strip away the complexity by converting content to a Bitmap whenever I can.&amp;#160; After reviewing the code, due to writing this blog, I decided building the conversion to a centered Bitmap in a Sprite into this static function was not a good design.&lt;/p&gt;  &lt;h5&gt;Code Narrative&lt;/h5&gt;  &lt;p&gt;The function has 3 arguments: 1) the radius; 2) a TextField containing the desired text and the formatting information; and 3) a Boolean where true means to place the text centered on the top and false means to center on the bottom.&lt;/p&gt;  &lt;p&gt;I use a TextField object to specify the input data.&amp;#160; I wanted to be able vary the format of each character.&amp;#160; Therefore I build the multi-formatted text outside of the function.&amp;#160; However it turns out the results of doing this are varied.&amp;#160; It is somewhat dependent of the actual font.&amp;#160; For example changing the 1st character font size or setting it to bold sometimes does not look that great.&amp;#160; Of course, it might not look that good when displayed in a straight line either.&amp;#160; On the other hand changing the color works well (despite potential bad taste).&lt;/p&gt;  &lt;p&gt;Don’t set the background color unless you are looking for some special&lt;img style="margin: 0px 0px 0px 5px" src="http://www.elegantfloraldesigns.us/blogstuff/FontWheels/FontWheelsCore.jpg" align="right" /&gt; effect.&amp;#160; The underline I created in my link to this blog, in the picture to the right, was drawn by hand.&amp;#160; This was a feature I tacked on at the end which contributes to the process not being as generic as I would like.&amp;#160; In order to know where to begin and end the underline circle you need internal information that is known at the time it was drawn.&lt;/p&gt;  &lt;p&gt;As I said providing the underlined circular text was a last minute requirement for the FP10 project.&amp;#160; I needed a way to change the color when the mouse hovers over the link text.&amp;#160; I chose to not convert the text and underline to bitmapData, but instead I left it as a complex sprite.&amp;#160; I drill down to each TextField and change each of their colors.&amp;#160; I also redraw the underline to change the color.&lt;/p&gt;  &lt;p&gt;Now that I’m done, I’ve had a chance to 2nd guess the approach.&amp;#160; My feelings at the moment would be to convert it to bitmapData and use its class functions to change the color.&amp;#160; This, of course, conflicts with the ability to restore different colors on the each character when the mouse rolls off the link.&amp;#160; A link shouldn’t be multi-colored but it just shows the complexity when you try to make one solution for all (like frameworks end up doing).&lt;/p&gt;  &lt;p&gt;&lt;em&gt;I hope this much detail in the design is useful to someone and doesn’t put everyone else to sleep.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The first thing I do is convert the input TextField to a bitmapData object.&amp;#160; I will use this object to extract each character into a bitmap.&lt;/p&gt;  &lt;p&gt;Next I compute how many degrees the text will consume.&amp;#160; Using that number I figure where I need to start placing the text based on the fact that I want the text centered at the top or bottom.&lt;/p&gt;  &lt;p&gt;Then, I loop through each character of the argument TextField.&amp;#160; I ignore spaces.&amp;#160; For each character, I create a Sprite and add a Bitmap containing that character to that Sprite.&amp;#160; Now the code is different depending on whether you want characters at the top or bottom.&amp;#160; Notice that the when the characters are at the top you are placing the bottom of the character around the circumference of the circle.&amp;#160; Then look at the pictures above and notice my name at the bottom of the circle.&amp;#160; Here, the top of the each character is drawn around circumference of the circle.&amp;#160; It took a while to get my head straight on this concept.&lt;/p&gt;  &lt;p&gt;Each character is then extracted into a new little bitmap.&amp;#160; These bitmaps are each inserted into their own Sprite.&amp;#160; I rotate each of these Sprites to the correct location.&amp;#160; I compute this location by getting the location from the input argument TextField.&amp;#160; Earlier I computed the number of degrees the whole field needs so that I could compute where to put the 1st character after centering.&amp;#160; I took the easy way out and simply apply the same fractional character positioning of the flat text field and apply that to the total number of degrees the field consumes on the curve to find the rotation to apply to the sprite.&amp;#160; I’m sure most of you have taken math more recently than the 60’s and would have done it a different way, but this way I only had to look up how to compute the circumference of a circle.&lt;/p&gt;  &lt;p&gt;But first where do you put the Bitmap character in the Sprite.&amp;#160; Imagine each Sprite to be like a spoke in a wheel with a character attached to the end and the other end at the center of the wheel.&amp;#160; As I mentioned earlier it depends on whether you are drawing the text around the top or on the bottom.&amp;#160; If on the top, the spoke connects to the bottom of the character and to the top of the character if the text goes on the bottom.&lt;/p&gt;  &lt;p&gt;There is a short coming in using the spoke in a wheel to describe this.&amp;#160; The hardest part of writing this code was placing the text on the bottom of the circle.&amp;#160; I’m sure I won’t explain this properly but if you need to dive into the code maybe this will give you a head start.&amp;#160; I kept trying to calculate the rotation of the Sprite’s when the text is on the bottom by computing the rotation at the bottom.&amp;#160; But that is wrong.&lt;/p&gt;  &lt;p&gt;Imagine the spoke for characters at the bottom to extend across the entire wheel instead of just to the center like the spokes for the top.&amp;#160; They still rotate at the center of the wheel but you control them by moving it at the top which is at the opposite end of where the Bitmap character is.&amp;#160; When you rotate the spoke at the top to the right the Bitmap at the bottom moves to the left.&lt;/p&gt;  &lt;p&gt;Obviously, you can tell I’m not a mathematician by describing it that way.&amp;#160; But that’s they way I figured it out.&lt;/p&gt;  &lt;p&gt;That’s basically it.&amp;#160; It isn’t a large function.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-2574608864519046300?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/2574608864519046300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=2574608864519046300' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/2574608864519046300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/2574608864519046300'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2008/07/flash-player-text-around-circle.html' title='Flash Player: Text Around A Circle'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-730385755550417295</id><published>2008-06-27T10:58:00.001-07:00</published><updated>2008-08-13T13:48:36.243-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SWF'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash Player 10'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash'/><category scheme='http://www.blogger.com/atom/ns#' term='Astro'/><title type='text'>More on: Flash Player 10 Beta Development Without Installing Anything</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I have now built an HTML page containing my &lt;a href="http://www.elegantfloraldesigns.us/blogstuff/FontWheels/FontWheels.html"&gt;FontWheels Flash Player 10 Beta Demo&lt;/a&gt; which is only useful if you have installed Flash Player 10 beta.&lt;/p&gt;  &lt;p&gt;However, to summarize my previous post, you may view Flash Player 10 Beta content without installing anything if you fear impacting your system with beta installables.&amp;#160; This can be done by downloading the &lt;strong&gt;external&lt;/strong&gt; Flash Player 10 beta: &lt;a href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/in/player/10/win/"&gt;FlashPlayer.exe&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;This is not an install executable.&amp;#160; It is the stand-alone external player and requires no installation.&amp;#160; To view content on the player, execute FlashPlayer.exe and enter the URL from the File/Open menu.&amp;#160; The URL to my swf demo is:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;http://www.elegantfloraldesigns.us/blogstuff/FontWheels/FontWheels.swf&lt;/strong&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-730385755550417295?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/730385755550417295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=730385755550417295' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/730385755550417295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/730385755550417295'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2008/06/more-on-flash-player-10-beta.html' title='More on: Flash Player 10 Beta Development Without Installing Anything'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-7847708553955449853</id><published>2008-06-26T15:45:00.001-07:00</published><updated>2008-06-27T04:54:54.890-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SWF'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash Player 10'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash'/><category scheme='http://www.blogger.com/atom/ns#' term='Astro'/><title type='text'>Flash Player 10 Beta Development Without Installing Anything</title><content type='html'>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;I wrote some ActionScript 3 code to try some of the new features in the Adobe Flash Player 10 beta and became so excited about it I can't put it down. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/FontWheels/FontWheels.jpg" align="right" /&gt; &lt;/p&gt;  &lt;p&gt;I have a demo, FontWheels, with some explanation below but first let me tell you how I build the swf. &lt;/p&gt;  &lt;p&gt;I had some problems getting started and still haven't work out some basic things. Fortunately, by accident, I found a way to do beta develop without having to install anything on my Windows XP machine.&amp;#160; At least to the best of my knowledge I didn't install anything and I can still use my Flex Builder 2 and Flash Debugger 9 with no conflicts. &lt;/p&gt;  &lt;p&gt;I initially tried following the instructions from Adobe about installing Flash Player 10 and the SDK. I was able to get it installed and ran through their examples and tutorials just fine. However I wasn't able to get it to work with Flex Builder 2 and then I started having problems trying to resume developing for Flash Player 9 with the debugger. &lt;/p&gt;  &lt;p&gt;I ended up removing everything (except the new SDK) and reinstalling Flex Builder 2 with the current debug player. &lt;em&gt;I'm not trying to discourage anyone from doing this. I'm sure I goofed somewhere.&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;But I thought I'd give it one more shot and by accident came up with something acceptable and as I said nothing needs to be installed. &lt;/p&gt;  &lt;p&gt;I ended up using the FlashDevelop version for FP10 from &lt;a href="http://www.FlashDevelop.org/"&gt;www.FlashDevelop.org.&lt;/a&gt; which for some reason is distributed as a compressed file with the rar extension. This gave me some problems coming up with something that worked with rar files instead of zip. However I eventually decompressed it. I created a shortcut on my desktop to the FlashDevelop.exe in the decompressed files and double clicked on the shortcut. Sure enough, FlashDevelop ran without any install. &lt;/p&gt;  &lt;p&gt;However I still need Flash Player 10 but found out I could use the &lt;b&gt;external &lt;/b&gt;Flash Player 10 beta instead of the versions for embedding into a browser. In the support page for FP10 at &lt;a href="http://www.FlashDevelop.org/"&gt;www.FlashDevelop.org&lt;/a&gt;&lt;a href="http://www.FlashDevelop.org/"&gt; &lt;/a&gt;there is a link to the standalone content debugger (&amp;quot;External player&amp;quot;): &lt;/p&gt;  &lt;p&gt;&lt;a href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/in/player/10/win/"&gt;http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/in/player/10/win/&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The external player requires no installation. (Note this is for Windows.) &lt;/p&gt;  &lt;p&gt;Next in the FlashDevelop Project\Properties menu I had to change the Target to Flash Player 10 and Test Player to “Play in external player”. &lt;/p&gt;  &lt;p&gt;Now I'm not sure how FlashDevelop knew where to find the standalone Flash Player and I'm not sure how it found the Flash Player 10 SDK. I was unable to follow their instructions to set up the SDK path but it ran anyway. I previously placed the SDK on my C: drive as C:\FLEX_SDK\ and edited C:\FLEX_SDK\frameworks\flex-config.xml according to the alternative directions from Adobe as follows: &lt;/p&gt;  &lt;p&gt;... &lt;/p&gt;  &lt;p&gt;&amp;lt;target-player&amp;gt;10.0.0&amp;lt;/target-player&amp;gt; &lt;/p&gt;  &lt;p&gt;... &lt;/p&gt;  &lt;p&gt;&amp;lt;external-library-path&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;path-element&amp;gt;libs/player/{targetPlayerMajorVersion}/playerglobal.swc&amp;lt;/path-element&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;/external-library-path&amp;gt; &lt;/p&gt;  &lt;p&gt;... &lt;/p&gt;  &lt;p&gt;&amp;lt;library-path&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;path-element&amp;gt;libs&amp;lt;/path-element&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;path-element&amp;gt;libs/player/{targetPlayerMajorVersion}&amp;lt;/path-element&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;path-element&amp;gt;locale/{locale}&amp;lt;/path-element&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;/library-path&amp;gt; &lt;/p&gt;  &lt;p&gt;FlashDevelop works quite well with the external player and handles the trace command just fine.&amp;#160; I had been using FlashDevelop until FlexBuilder came along but it has changed a lot since then.&amp;#160; It handles the new vector syntax of Flash 10.&amp;#160; The behavior of the code completion is different from Flex Builder.&amp;#160; I think Flex Builder is smoother but FlexDevelop tries to do more with code completion.&amp;#160; It seems to fail to “code complete” more frequently than Flex Builder and I find it mildly annoying because I have to use the escape key to get out of the code completion mode much too often.&amp;#160; In all fairness I haven't tried much customization to get rid of the annoyances and overall I like FlexDevelop.&amp;#160; It has a bunch of useful feature many of which I haven't mastered.&amp;#160; If I ever figure out how to make a living out of this I definitely plan on donating something for this product. &lt;/p&gt;  &lt;p&gt;So here is my demo but you might have go through some hoops to see it.&amp;#160; Since I am using the external Flash 10 Player I don't have a way of testing a SWF within a web page. So if you want to see my demo, download the External Play Player 10 from the link mentioned above. Then in the menu File open enter the following: &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;http://www.elegantfloraldesigns.us/blogstuff/FontWheels/FontWheels.swf&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Of course, if you are able to view Flash 10 content from your browser, you should be able to view the swf file by entering the above URL.&amp;#160; I’ve never seen it that way so I can only hope it runs. &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;FontWheels, the Flash 10 Beta Demo&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;I was working on&amp;#160; an ActionScript 3&amp;#160; for Player 9 project where I wanted to display characters around a circle dynamically.&amp;#160; I don’t like having to embed fonts so I thought I would see how bad it would be to first convert characters to a bitmap and then rotate them.&amp;#160; The result was far from perfect but since the size of the characters were fairly small it didn’t look as bad as I expected.&amp;#160; Certain letters, like “W” looked pretty bad but I decided I could live with it.&amp;#160; Since I first heard about Flash Player 10 beta while I was working on rotating the fonts I used that code as the starting place for testing the new player.&lt;/p&gt;  &lt;p&gt;Using the exact code, that is first converting to bitmaps and the rotating, there was amazing improvement.&amp;#160; This wasn’t something I was anticipating.&amp;#160; I hadn’t read anything about the new player improving the results of rotating a bitmap, but there is no doubt it is a lot better.&lt;/p&gt;  &lt;p&gt;Well, that created a lot of interest on my part so I decided to try rotating a TextField instead of a bitmap but still not embedding a font.&amp;#160; We let me tell you it looks a whole lot better than the bitmap.&lt;/p&gt;  &lt;p&gt;Next I wondered what would it look like if I rotated the characters around the circle live.&amp;#160; My initial app was to build a static medallion with characters around a curve but I couldn’t resist seeing them rotate on the screen.&amp;#160; Then I wondered if I could do this will all of my device fonts.&amp;#160; Yes.&amp;#160; The player could handle displaying all of my approximately 110 device fonts on the screen rotating simultaneously.&amp;#160; Later on after trying it on my granddaughter’s older computer I decide it would be best to limit the total number of fonts.&lt;/p&gt;  &lt;p&gt;Then I wanted to play with the 3D&amp;#160; capability.&amp;#160; I discovered that rotating each letter on another axis and the rotating the font wheel on another axis I could get what appears to be a circular marquee.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/FontWheels/Marquee.jpg" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;So there it is.&amp;#160; I hope you take the time to see it run.&amp;#160; I’ve rush this post out because I’m anxious to get back and try some other new things.&amp;#160; I hope I’m not leaving in too many misspellings and grammar errors but I’m in a hurry!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-7847708553955449853?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/7847708553955449853/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=7847708553955449853' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/7847708553955449853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/7847708553955449853'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2008/06/flash-10-beta-development-without.html' title='Flash Player 10 Beta Development Without Installing Anything'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-6444910769456564515</id><published>2007-07-24T05:53:00.000-07:00</published><updated>2007-07-24T06:33:11.957-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>ActionScript 3, E4X Snippet</title><content type='html'>&lt;p&gt;I have been working on an E4X function to transform XML attributes into elements for&amp;nbsp;displaying in a Tree.&amp;nbsp; I have&amp;nbsp;a working function, not exactly in the form I wanted, but I am lacking a good example of it to post this week.&amp;nbsp; This is all tied into the work I have posted in the last few weeks about sorting XML for trees.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Code snippet&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;There was one little code snippet which was part of solving the problem I thought I would share with you now.&amp;nbsp; Unlike my XML sort routines where I modify the source object, this routine creates a duplicate XML object but with elements instead of attributes.&lt;/p&gt; &lt;p&gt;The problem I had was coming up with code to copy the root element of the source code to a new XML object.&amp;nbsp; It wasn't so straight forward with E4X.&amp;nbsp; I think concise code could have been written to simply copy the object with the copy() function and the delete its children but I was concerned this could be inefficient especially if the object was large.&lt;/p&gt; &lt;p&gt;This is what I did:&lt;/p&gt; &lt;p&gt;&lt;pre style="font-size: 80%; margin-left: 0px; color: blue"&gt; 1 public static function transformXmlAttributeToElement
 2     ( avXmlIn               :XML,
 3       avAttributeName       :String,
 4       avArrayAttributeNames :Array )
 5     :XML
 6 {
 7     var lvXmlOut:XML = &amp;lt;{avXmlIn.name()}/&amp;gt;;
 8     for each( var lvXmlAttribute:XML
 9                in avXmlIn.attributes() )
10        lvXmlOut.@[lvXmlAttribute.name()] = lvXmlAttribute;
    ...
&lt;/pre&gt;
&lt;p&gt;Line 7 creates a root element with the same name as the source.&amp;nbsp; Lines&amp;nbsp;8 and 9&amp;nbsp;loop through all of the attributes in the&amp;nbsp;source root element&amp;nbsp;with line&amp;nbsp;10 creating a duplicate of each attribute in the destination element.&lt;/p&gt;
&lt;p&gt;My generic functions can't use hard coded names, but most examples you&amp;nbsp;find on the Internet use hard coded names.&amp;nbsp; I thought maybe someone needing to do something similar could benefit from the example.&amp;nbsp; I prefer to&amp;nbsp;write more comprehensive posts than this but I'm just not ready this week.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Addendum&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;My post&amp;nbsp;&lt;a href="http://freerpad.blogspot.com/2007/07/more-hierarchical-sorting-e4x-xml-for.html" target="_blank"&gt;More Hierarchical Sorting E4X XML: for Flex Tree &amp;amp; Beyond&lt;/a&gt;&amp;nbsp;was my 1st attempt to make use of publishing a Flex application along with the &lt;strong&gt;Publish Application Source&lt;/strong&gt; feature of Flex Builder 2.&amp;nbsp; Boy am I dumb.&amp;nbsp; For some reason it got into my head that every time&amp;nbsp;I recompile, the new source code would be regenerated.&amp;nbsp; Not true.&amp;nbsp;&amp;nbsp;If you&amp;nbsp;downloaded the source code before last Friday, you got old source code.&amp;nbsp; I've fixed that.&lt;/p&gt;
&lt;p&gt;I also fixed a state transition flicker problem that crept back into the example.&amp;nbsp; There appears to be a little bit of art in handling flicker in state changes.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-6444910769456564515?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/6444910769456564515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=6444910769456564515' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/6444910769456564515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/6444910769456564515'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/07/actionscript-3-e4x-snippet.html' title='ActionScript 3, E4X Snippet'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-2307457709259398483</id><published>2007-07-18T06:42:00.000-07:00</published><updated>2007-07-18T16:55:09.466-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Flash'/><title type='text'>ActionScript 3, Undocumented Features?</title><content type='html'>&lt;p&gt;You have been&amp;nbsp;entrusted to be in on some secret features of ActionScript 3.&amp;nbsp; Only a handful of programmers around the world will see&amp;nbsp;this 

information.&amp;nbsp; &lt;em&gt;This is mostly due to the fact&amp;nbsp;you have been able to hack&amp;nbsp;your way into one of the most obscure blogs on the planet!&lt;/em&gt;&lt;/p&gt; 

&lt;p&gt;Actually, I don't know if I am breaking new ground here but I haven't been able to find any&amp;nbsp;mention of&amp;nbsp;this feature.&amp;nbsp; I&amp;nbsp;really 

discovered&amp;nbsp;it sometime ago&amp;nbsp;while writing&amp;nbsp;an &lt;a href="http://freerpad.blogspot.com/2007/06/more-getting-xml-elements-and.html" 

target="_blank"&gt;earlier post&lt;/a&gt; but I didn't know the extent of the find.&lt;/p&gt; &lt;p&gt;And the find is fairly extensive but I've come up with only&amp;nbsp;a 

few&amp;nbsp;practical uses and one of those was already discussed in the mentioned post.&amp;nbsp; I don't know how far back these features go.&amp;nbsp; It may be 

they&amp;nbsp;were around before ActionScript 2; before I ever used Flash.&amp;nbsp; Maybe veteran Flash developers find it so ho-hum&amp;nbsp;they forget to pass it on 

to&amp;nbsp;newbies.&amp;nbsp; I haven't tried this with AS2 because I don't want to fire up Flash again and have to re-learn anything.&amp;nbsp; BE WARNED: Be careful how 

you use undocumented features.&amp;nbsp; Also, "undocumented" means I haven't been able to find anything about them in the Adobe documentation.&lt;/p&gt; &lt;p&gt;Please let me 

know if you can find this someplace.&amp;nbsp; &lt;em&gt;Someone needs to write a book about how to best use and find available resources for Flash, Flex and 

ActionScript.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;The Secret Features:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;You can&amp;nbsp;insert multiple comma separated expressions when the syntax calls for an 

expression between parentheses.&lt;/p&gt; &lt;p&gt;For example:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;do&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // do something&lt;br&gt;} while( a = b, a == 0 );&lt;/strong&gt;  &lt;p&gt;The 

&lt;strong&gt;while&lt;/strong&gt; test will be performed on the rightmost expression, &lt;strong&gt;a == 0&lt;/strong&gt;, but variable &lt;strong&gt;a&lt;/strong&gt; will be set to the value of 

&lt;strong&gt;b&lt;/strong&gt; prior to the test.&amp;nbsp; You are not limited in the number of expressions but you are limited in the type of expression.&amp;nbsp; For example, you 

cannot declare a variable with a&amp;nbsp;&lt;strong&gt;var&lt;/strong&gt;&amp;nbsp;and you can't&amp;nbsp;use an &lt;strong&gt;if&lt;/strong&gt; statement.&amp;nbsp; The expression must&amp;nbsp;resolve to 

a value.&amp;nbsp; The &lt;strong&gt;? :&lt;/strong&gt; expression can be used and you can call a &lt;strong&gt;function&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;The &lt;strong&gt;do while&lt;/strong&gt; statement, the 

&lt;strong&gt;while&lt;/strong&gt; statement and the E4X &lt;strong&gt;filter predicate expression&lt;/strong&gt; are the best candidates for this feature.&amp;nbsp; However it can also be 

done in the &lt;strong&gt;return&lt;/strong&gt; and &lt;strong&gt;switch&lt;/strong&gt; statements although I can't see&amp;nbsp;any value in using it.&amp;nbsp; The &lt;strong&gt;return 

&lt;/strong&gt;statement doesn't even require parentheses.&lt;/p&gt; &lt;p&gt;I was hoping to show a compelling example using &lt;strong&gt;do while&lt;/strong&gt; or &lt;strong&gt;while 

&lt;/strong&gt;but haven't been able to think of one.&amp;nbsp; I made this discovery when I was creating a loop and using IViewCursor to iterate over an 

XMLListCollection.&amp;nbsp; The &lt;strong&gt;where&lt;/strong&gt; clause was getting too long to fit into a line and I wanted to break it up.&amp;nbsp; So I thought, what the heck, 

why not try it.&lt;/p&gt; &lt;p&gt;You can also do something similar with the &lt;strong&gt;for&lt;/strong&gt; statement:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;for( I = 0, N = 2; N &amp;lt; 5,I &amp;lt; 3; I++, N++ 

){}&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I think I recall seeing examples of&amp;nbsp;the &lt;strong&gt;for&lt;/strong&gt; statement&amp;nbsp;before, but I don't remember if it was for ActionScript.&lt;/p&gt; 

&lt;p&gt;I guess when the ActionScript parser&amp;nbsp;encounters the open parenthesis&amp;nbsp;it handles it as though it is a function call with arguments without paying too 

much attention to the context.&amp;nbsp; It's okay, I won't tell Adobe if you won't.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-2307457709259398483?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/2307457709259398483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=2307457709259398483' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/2307457709259398483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/2307457709259398483'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/07/actionscript-3-undocumented-features.html' title='ActionScript 3, Undocumented Features?'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-4632282131111055399</id><published>2007-07-09T06:35:00.000-07:00</published><updated>2007-07-09T06:38:49.193-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Tree'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><title type='text'>More Hierarchical Sorting E4X XML: for Flex Tree &amp; Beyond</title><content type='html'>&lt;p&gt;This&amp;nbsp;is a continuation of my most recent posts.&amp;nbsp; I've changed the Tree's dataProvider to an XMLListCollection 

object instead of an XML object as discussed in&amp;nbsp;a &lt;a 

href="http://freerpad.blogspot.com/2007/06/addendum-as3-e4x-sorting-hierarchical.html"&gt;recent post&lt;/a&gt;&amp;nbsp;in this 

series.&lt;/p&gt; &lt;p&gt;My hierarchical sort&amp;nbsp;function still works&amp;nbsp;with an XML object so it may be used for other purposes 

besides a Flex Tree.&amp;nbsp; The sort function is&amp;nbsp;only dependent on&amp;nbsp;the&amp;nbsp;resources&amp;nbsp;built in&amp;nbsp;the Flash 

Player.&lt;/p&gt; &lt;p&gt;The earlier&amp;nbsp;&lt;a href="http://freerpad.blogspot.com/2007/06/actionscript-e4x-example-sorting.html"&gt;sort 

function&lt;/a&gt; had a&amp;nbsp;limitation&amp;nbsp;which required sorting&amp;nbsp;an attribute that needed to be in all elements of the XML 

object.&amp;nbsp; The new sort function&amp;nbsp;no longer has that requirement.&amp;nbsp; This opens the door for even more 

functionality.&lt;/p&gt; &lt;p&gt;The new function still only sorts on a single attribute but if you combine that with some &lt;strong&gt;old 

tech&lt;/strong&gt; you can do quite a bit.&lt;/p&gt; &lt;p&gt;&lt;img style="margin: 0px 5px 0px 0px" alt="Old Tech" 

src="http://www.elegantfloraldesigns.us/blogstuff/cardsorter.jpg" align="left"&gt;Do you know what this is?&amp;nbsp; No, it's not 

a&amp;nbsp;computer&amp;nbsp;but it frequently worked as a stunt double for computers in 60's and 70's movies.&amp;nbsp; It is a card 

sorter and I&amp;nbsp;have used one&amp;nbsp;many times.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;em&gt;I still vividly recall a conversation I was having with my 

programmer son a few years ago.&amp;nbsp; We were driving up Highway 6 and it's one of those events in your life when you remember 

where you were.&amp;nbsp; We were having a recurring argument about cutting 25 years&amp;nbsp;from my resume.&amp;nbsp; My son asked me 

what could you possibly use today that you learned in those days.&amp;nbsp; I guess I remember&amp;nbsp;this incident&amp;nbsp;so well 

because it forced up the reality that so much of my professional self esteem is based on things nobody cares about 

today.&amp;nbsp;&amp;nbsp;It was a good question albeit a little cold.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;Well&amp;nbsp;here it is: I can use my experience of 

operating a card sorter today!&amp;nbsp; And do you know how&amp;nbsp;to sort on one, son?&amp;nbsp; Of course you don't!&amp;nbsp;&amp;nbsp;A 

field in a card must be sorted one column at a time backwards.&amp;nbsp; Multiple fields must be sorted in reverse order.&amp;nbsp; 

For example if you wanted to sort by last name&amp;nbsp;in columns 1 thru 10 and&amp;nbsp;first name&amp;nbsp;in columns 11 thru 

20&amp;nbsp;you&amp;nbsp;would sort on columns 20,19,18...3,2,1; one at a time.&lt;/p&gt; &lt;p&gt;And if you combine this &lt;strong&gt;old 

tech&lt;/strong&gt; with my simple function you can sort multiple attribute fields each one independently of the others.&amp;nbsp; That 

means you can sort some ascending, some descending, some dates, some numbers, etc. You can do it backwards (with one hand tied 

behind your back).&amp;nbsp; Hah!&lt;/p&gt; &lt;p&gt;No, you don't have to sort a character at a time.&lt;/p&gt; &lt;p&gt;Here is the new ActionScript 3 

E4X sort XML attributes function:&lt;/p&gt;&lt;pre style="font-size: 80%; margin-left: 10px; color: blue"&gt; 1 public static function 

sortXmlAttribute
 2     ( avXml                :XML,
 3       avAttributeName      :String,
 4       avPutEmptiesAtBottom :Boolean,
 5       avArraySortArgument0 :* = 0,
 6       avArraySortArgument1 :* = 0 )
 7     :void
 8 {
 9     var lvChildrenCount:int
10         = avXml.children().length();
11     
12     if( lvChildrenCount == 0 )
13         return;
14 
15     if( lvChildrenCount &amp;gt; 1 )
16     {
17         var lvAttributeValue    :String;
18         var lvXml               :XML;
19 
20         var lvSortOptions:int
21             = avArraySortArgument0 is Function
22               ? avArraySortArgument1
23               : avArraySortArgument0;
24             
25         var lvSortCaseInsensitive:Boolean
26             = ( lvSortOptions &amp;amp; Array.CASEINSENSITIVE )
27               == Array.CASEINSENSITIVE;
28               
29         var lvArray:Array = new Array();
30         
31         for each( lvXml in avXml.children() )
32         {
33           lvAttributeValue
34               = lvXml.attribute( avAttributeName );
35 
36           if( lvSortCaseInsensitive )
37               lvAttributeValue
38                   = lvAttributeValue.toUpperCase();
39                 
40           if( lvArray.indexOf( lvAttributeValue ) == -1 )
41               lvArray.push( lvAttributeValue );
42                 
43         } // for each
44         
45         if( lvArray.length &amp;gt; 1 )
46         {
47             lvArray.sort
48             (
49                 avArraySortArgument0,
50                 avArraySortArgument1
51             );
52             
53             if( avPutEmptiesAtBottom )
54             {
55                 if( lvArray[0] == "" )
56                     lvArray.push( lvArray.shift() );
57             } // if
58             
59         } // if
60             
61         var lvXmlList:XMLList = new XMLList();
62         for each( lvAttributeValue in lvArray )
63         {
64             for each( lvXml in avXml.children() )
65             {
66               var lvXmlAttributeValue:String
67                    = lvXml.attribute
68         ( avAttributeName );
69                      
70               if( lvSortCaseInsensitive )
71                   lvXmlAttributeValue
72                     = lvXmlAttributeValue.toUpperCase();
73                 
74               if( lvXmlAttributeValue
75                   ==
76                   lvAttributeValue )
77                   lvXmlList += lvXml;
78                     
79             } // for each
80             
81         } // for each
82         
83         avXml.setChildren( lvXmlList );
84         
85     } // if             
86 
87     for each( var lvXmlChild:XML in avXml.children() )
88     {
89         sortXmlAttribute
90         (
91             lvXmlChild,
92             avAttributeName,
93             avPutEmptiesAtBottom,
94             avArraySortArgument0,
95             avArraySortArgument1
96         );
97     } // for each
98     
99 } // sortXmlAttribute
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Function sortXmlAttribute Description&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Arguments&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="2" width="401" border="1" unselectable="on"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="36"&gt;&lt;strong&gt;#&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="172"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="71"&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="120"&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="35"&gt;1&lt;/td&gt;
&lt;td valign="top" width="172"&gt;avXml&lt;/td&gt;
&lt;td valign="top" width="71"&gt;XML&lt;/td&gt;
&lt;td valign="top" width="120"&gt;Object to be sorted.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="35"&gt;2&lt;/td&gt;
&lt;td valign="top" width="172"&gt;avAttributeName&lt;/td&gt;
&lt;td valign="top" width="71"&gt;String&lt;/td&gt;
&lt;td valign="top" width="120"&gt;Attribute Name to sort&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="35"&gt;3&lt;/td&gt;
&lt;td valign="top" width="172"&gt;avPutEmptiesAtBottom&lt;/td&gt;
&lt;td valign="top" width="71"&gt;Boolean&lt;/td&gt;
&lt;td valign="top" width="120"&gt;Where to put elements that have empty values for sorted attribute.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="35"&gt;4&lt;/td&gt;
&lt;td valign="top" width="172"&gt;avArraySortArgument0&lt;/td&gt;
&lt;td valign="top" width="71"&gt;*&lt;/td&gt;
&lt;td valign="top" width="120"&gt;Array.sort() 1st argument&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="35"&gt;5&lt;/td&gt;
&lt;td valign="top" width="173"&gt;avArraySortArgument1&lt;/td&gt;
&lt;td valign="top" width="72"&gt;*&lt;/td&gt;
&lt;td valign="top" width="124"&gt;Array.sort()&amp;nbsp;2nd argument&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There were two big changes from the earlier function.&amp;nbsp; One, I have removed E4X filtering and used the more 

conventional E4X syntax.&amp;nbsp; This really simplified the function.&amp;nbsp; I'm not putting down the filtering feature, but in 

this instance I am better off without it.&lt;/p&gt;
&lt;p&gt;The second was dealing with case insensitive sorts.&amp;nbsp; The problem I had before was that I ended up separating strings 

that had different cases but were otherwise equal.&amp;nbsp; This isn't a problem when you are doing a single sort, but when you 

stack sorts back to back the problem shows up.&lt;/p&gt;
&lt;p&gt;I also added a feature that controls where you put the XML elements that do not have&amp;nbsp;an attribute value.&amp;nbsp; The 

need do this varies with the type of data you are looking at.&amp;nbsp; It was actually easy to implement.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines&amp;nbsp;20 thru 27&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This code determines if the sort is case insensitive.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines&amp;nbsp;29 thru 43&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This section builds an array of unique attribute values.&amp;nbsp; If the sort is case insensitive I convert all of the values 

to upper case.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines 47 thru 51&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This sorts the array with the Array.sort() function.&amp;nbsp; That's all I ever sort; just the unique attribute values.&amp;nbsp; 

This is important.&amp;nbsp; I don't sort the XML object (because I can't).&amp;nbsp; I never upset the order of the children which 

may have been sorted on another field previously.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines 53 thru 57&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is where I move the XML elements that have empty attribute values if necessary.&amp;nbsp; It just moves an empty string 

from the beginning of the array to the end.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines 61 thru 81&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is where the real meat of the function is.&amp;nbsp; I want to build a new XMLList object that represents all of the XML 

children but in the new sorted order.&amp;nbsp; I iterate through each of the sorted unique attribute values.&amp;nbsp; Inside that 

iteration I iterate through all of the XML children.&amp;nbsp; If the child has the current attribute value I append it to the end 

of the temporary XMLList I'm building.&amp;nbsp; I have to allow for case insensitivity.&amp;nbsp; It is important make sure that 

children with the same value stay in the same order.&amp;nbsp; This actually means doing nothing and I do it well.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Line 83&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I replace the children of the input XML object with the temporary XMLList I just built with the E4X setChildren 

function.&amp;nbsp; It is really nice to have this very simple function.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines 87 thru 97&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This makes the function recursive.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;That is the function.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It is very straightforward.&amp;nbsp; If all algorithms were like this, most everyone could be a programmer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Example&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Previously, I have included the source code in the post but no compiled example.&amp;nbsp; I know personally I prefer to just 

look&amp;nbsp;at the code and if I'm interested I'll compile it myself.&amp;nbsp; I've also kept the examples to one file.&amp;nbsp; I 

started this post and the example in the same manner, but the example just kept getting bigger.&amp;nbsp; It is still only one 

file, but in the future I will have to break it into more than one class.&amp;nbsp; I've decided to provide a &lt;a 

href="http://www.elegantfloraldesigns.us/blogstuff/CardSorterExample.html" target="_blank"&gt;page with the source 

code&lt;/a&gt;.&amp;nbsp; My intention is to do this in the future, but the&amp;nbsp;page will probably contain more than one file.&amp;nbsp; In 

addition I&amp;nbsp;have a&amp;nbsp;link to&amp;nbsp;a&amp;nbsp;page that contains &lt;a 

href="http://www.elegantfloraldesigns.us/blogstuff/CardSorter/XmlListCollectionSort.html" target="_blank"&gt;the SWF 

file&lt;/a&gt;.&amp;nbsp; I will also compile with the "Publish Source Code" option.&amp;nbsp; This will give you the ability to view the 

source code from the SWF program.&amp;nbsp; You'll also be able to download the program in a zip file along with the Flex 2 

SDK.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://www.elegantfloraldesigns.us/blogstuff/CardSorter/XmlListCollectionSort.html" target="_blank" 

atomicselection="true"&gt;&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/CardSorterExample.jpg"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The new example has a&amp;nbsp;lot more goodies in it.&amp;nbsp; There are 2 built-in examples but you can also paste in your own 

XML.&amp;nbsp; So it actually can be used as an XML sort tool.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Next&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I'm now starting to think about sorting element names and values.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Addendum&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I came across someone wanting to sort XML via the E4X capabilities of JavaScript.&amp;nbsp; I think my function will 

work.&amp;nbsp; You might have to remove the static declaration. (I don't know.)&lt;/p&gt;
&lt;p&gt;There are several functions in the example declared as static.&amp;nbsp; This is my way of implying the function stands on its 

own and it may have other uses.&lt;/p&gt;
&lt;p&gt;I wouldn't mind expanding to other platforms if for no other reason than to improve my visibility.&amp;nbsp; (I probably only 

have a total of 30 lifetime hits.)&amp;nbsp; Please point me in the right direction on how to set up a test environment of E4X 

JavaScript.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-4632282131111055399?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/4632282131111055399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=4632282131111055399' title='21 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/4632282131111055399'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/4632282131111055399'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/07/more-hierarchical-sorting-e4x-xml-for.html' title='More Hierarchical Sorting E4X XML: for Flex Tree &amp;amp; Beyond'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>21</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-4151272003833268067</id><published>2007-07-02T10:43:00.000-07:00</published><updated>2007-07-02T10:44:45.021-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><title type='text'>ActionScript 3 isNaN is BaD</title><content type='html'>&lt;p&gt;A primary rule&amp;nbsp;of my programming style is to keep things positive whenever 

possible.&amp;nbsp; For example it always clearer to test for things to be equal&amp;nbsp;than to test 

for&amp;nbsp;them to be not equal.&amp;nbsp; So I'm not surprised&amp;nbsp;there are many discussions about 

the ActionScript isNaN function on the Internet.&amp;nbsp; NaN stands for "not a number".&amp;nbsp; Its 

&lt;a href="http://en.wikipedia.org/wiki/NaN"&gt;roots&lt;/a&gt; go deeper than ActionScript.&amp;nbsp; It 

is&amp;nbsp;self-evident why the term was coined and equally predictable to be a subject of 

confusion.&lt;/p&gt; &lt;p&gt;However, the function's negativity can only be charged with creating "bad 

vibes"&amp;nbsp;in the&amp;nbsp;misdeeds mentioned in this post.&amp;nbsp; The following comes from the 

Adobe documentation:&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;img 

src="http://www.elegantfloraldesigns.us/blogstuff/isNaNDoc.jpg"&gt; &lt;/p&gt; &lt;p&gt;The last&amp;nbsp;two 

table rows&amp;nbsp;in the documentation pass strings&amp;nbsp;to the isNaN function.&amp;nbsp; However, I 

get a fatal compile error when I try to do this.&amp;nbsp; The same documentation&amp;nbsp;clearly 

specifies&amp;nbsp;the argument type is "Number".&amp;nbsp; The editor's&amp;nbsp;"Intellisense?" (I don't 

know what Adobe calls it)&amp;nbsp;says&amp;nbsp;the argument is a "Number".&lt;/p&gt; &lt;p&gt;But&amp;nbsp;I can find 

plenty of examples on the Internet showing string arguments.&amp;nbsp; I think some of these 

examples may be explained by the fact that they don't&amp;nbsp;specify&amp;nbsp;the type in the var 

declaration.&amp;nbsp; When I do this, I&amp;nbsp;get a compiler warning.&amp;nbsp; I wouldn't post an 

example that produced a compiler warning, at least without pointing it out, but maybe I'm in 

the minority.&lt;/p&gt; &lt;p&gt;Other examples may be about earlier versions of ActionScript or maybe beta 

versions.&amp;nbsp; It's sometimes hard sort these things out.&amp;nbsp; I am using Flex Builder 2 and 

have also tried this with the Flex Builder 3 beta.&amp;nbsp; I got around the warning message by 

using the asterisk as the variable type.&amp;nbsp; I don't like using an asterisk as a workaround, 

but in this case I think that is&amp;nbsp;how the argument is&amp;nbsp;internally defined.&amp;nbsp; This 

is because the function actually works when I pass a string to the function.&lt;/p&gt; &lt;p&gt;I really 

only wanted to write a function to determined if a string contained a valid number.&amp;nbsp; The 

following&amp;nbsp;example works.&amp;nbsp; Notice the asterisk in the "for each" statement.&lt;/p&gt;&lt;pre 

style="font-size: 90%; margin-left: 10px; color: blue"&gt;&amp;lt;?xml version="1.0" 

encoding="utf-8"?&amp;gt;
&amp;lt;mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="onCreationComplete()"
    &amp;gt;
    &amp;lt;mx:TextArea
        id="Text1"
        height="400"
        /&amp;gt;
    
    &amp;lt;mx:Script&amp;gt;
        &amp;lt;![CDATA[
        // -----------------------------------------
        // onCreationComplete
        // -----------------------------------------

        private function onCreationComplete
            ()
            :void
        {
            var lvString:String = "";
            
            for each( var lvValue:*
                  in ["5", "A", "-1", "-.7", "*" ] )
                lvString += lvValue
                          + ": NaN is "
                          + isNaN( lvValue ).toString()
                          + "\n";
            
            Text1.text += lvString;

        } // onCreationComplete
        ]]&amp;gt;
    &amp;lt;/mx:Script&amp;gt;
    
&amp;lt;/mx:Application&amp;gt;&lt;/pre&gt;
&lt;p&gt;Text1 contains the following when the example is run:&lt;/p&gt;&lt;pre style="font-size: 90%; 

margin-left: 20px; color: blue"&gt;5: NaN is false
A: NaN is true
-1: NaN is false
-.7: NaN is false
*: NaN is true
&lt;/pre&gt;
&lt;p&gt;This has been a minor distraction while developing an example program for a new post on my 

series of Sorting XML which I hope to have ready this week.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-4151272003833268067?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/4151272003833268067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=4151272003833268067' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/4151272003833268067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/4151272003833268067'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/07/actionscript-3-isnan-is-bad.html' title='ActionScript 3 isNaN is BaD'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-6061988057759735190</id><published>2007-06-25T06:59:00.000-07:00</published><updated>2007-06-25T07:00:27.401-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Tree'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><title type='text'>addendum AS3 E4X: Sorting Hierarchical XML Data for Tree Control</title><content type='html'>&lt;p&gt;I’ve taken some private and thankfully friendly flak about my &lt;a href="http://freerpad.blogspot.com/2007/06/actionscript-e4x-example-sorting.html"&gt;preceding post&lt;/a&gt; on sorting data in an XML object for the purpose of providing data to a tree control.&amp;nbsp; I'm told I should use the ItreeDataDescriptor interface to get into the real spirit of Flex.&lt;/p&gt; &lt;p&gt;I did a little homework and learned a few things that should have been part of the &lt;a href="http://freerpad.blogspot.com/2007/06/actionscript-e4x-example-sorting.html"&gt;preceding post&lt;/a&gt;.&amp;nbsp; At this point, I'm not going to create a class implementing ItreeDataDescriptor but I’ll keep an open mind on the subject.&amp;nbsp; However I did have some misunderstandings about what I was doing.&amp;nbsp; (I did mention on my first post, this blog would be a journal of my experiences and I’m new to Flex.)&lt;/p&gt; &lt;p&gt;When you set the Tree control’s dataProvider property to an XML object, it gets converted internally to an XMLListCollection which I have verified by running a trace.&lt;/p&gt; &lt;p&gt;The official Adobe documentation is wrong.&amp;nbsp; It does say that 3&amp;nbsp;object types&amp;nbsp;get converted to an XMLListCollection: a valid XML string, an XMLNode, and an XMLList.&amp;nbsp; I suppose it is reasonable to assume if a valid XML string is converted along with an XMLList object, then an XML object would be also.&lt;/p&gt; &lt;p&gt;Okay, I didn't actually read the documentation on a Tree's dataProvider before writing my code.&amp;nbsp; I assumed all dataProvider's would be the same.&amp;nbsp;I'm not sure where my basic knowledge of dataProvider's came from but it was probably from Adobe's "Training from the Source".&amp;nbsp; And anyway, the documentation is wrong.&lt;/p&gt; &lt;p&gt;The first thing I should have done, and I don't know why I don't do this all of the time, is look at the Flex source code.&amp;nbsp; Sometimes it takes a while to weed through the code, but this time it took all of 30 seconds to verify:&amp;nbsp; &lt;strong&gt;When you set a Tree's dataProvider to an XML object, it gets converted internally to an XMLListCollection object.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The embarrassing thing about my previous post is that I was contrasting how well I could get an XML object to work but blasting the XMLListCollection as a Tree’s dataProvider.&amp;nbsp; My real problem was trying to sort descendents and I haven’t figured how to do that with XMLListCollection’s.&amp;nbsp; I’m sticking with the XML sort and plan to expand upon it real soon. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-6061988057759735190?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/6061988057759735190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=6061988057759735190' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/6061988057759735190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/6061988057759735190'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/06/addendum-as3-e4x-sorting-hierarchical.html' title='addendum AS3 E4X: Sorting Hierarchical XML Data for Tree Control'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-3891268797767502714</id><published>2007-06-22T09:41:00.000-07:00</published><updated>2007-06-26T07:54:24.555-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><title type='text'>ActionScript E4X: Example Sorting Hierarchical XML Data for Tree Control</title><content type='html'>I’ve been able to find examples of how to sort XMLListCollection objects which are useful data providers for controls 

like the DataGrid. But I wanted to sort hierarchical data for a Tree control. XMLListCollection objects sort top 

level elements but apparently don’t sort children, grandchildren, etc. At least I couldn’t figure out how to do 

it.&lt;br/&gt;&lt;br/&gt;

I needed the tree sort for an AIR application.  I built a sort function for XML objects and plugged an XML object 

into the Tree’s data provider.  It works.  I decided this function would be a good post by itself so I put together a 

Flex 2 example with only one mxml file which is provided at the bottom of the post.&lt;br/&gt;&lt;br/&gt;

Tree node labels are specified with the property “labelField” and normally you would want to sort on these 

labels.&lt;br/&gt;&lt;br/&gt;

&lt;i&gt;Actually, you might want to first sort on the node type and then the labels, but I haven’t gotten far enough in my 

application to need that yet.  I know I’ll need it in the future, so stay tuned.&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;

I set the Tree’s “labelField” property to one of the attribute names of the elements in the XML object.  The example 

uses the “name” attribute preceded by the “@” character which is the E4X designator for attributes.&lt;br/&gt;&lt;br/&gt;

&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;
&amp;lt;mx:Tree dataProvider="{mvXml}" labelField="@name"/&amp;gt;&lt;/pre&gt;

The data provider variable “mvXml” is defined as:&lt;br/&gt;&lt;br/&gt;

&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;
var mvXml:XML =
    &amp;lt;Country name= "USA"&amp;gt;
     &amp;lt;State name="Texas"&amp;gt;
       &amp;lt;City name="Corpus Christi"/&amp;gt;
       &amp;lt;City name="austin"/&amp;gt;
       &amp;lt;City name="San Antonio"/&amp;gt;
     &amp;lt;/State&amp;gt;
     &amp;lt;State name="Michigan"&amp;gt;
       &amp;lt;City name="Ypsilanti"/&amp;gt;
       &amp;lt;City name="lansing"/&amp;gt;
       &amp;lt;City name="Ann Arbor"/&amp;gt;
       &amp;lt;City name="Kalamazoo"/&amp;gt;
       &amp;lt;City name="Allen Park"/&amp;gt;
     &amp;lt;/State&amp;gt;
   &amp;lt;/Country&amp;gt;&lt;/pre&gt;

&lt;b&gt;Now the fine print&lt;/b&gt;&lt;br/&gt;

&lt;p style="font-family:arial;font-size:85%;color:LightGray"&gt;
It is not unusual to have alphanumeric, numeric, currency and date nodes in a single tree.  Of course all of the tree 

node labels can be sorted as simple text, but if you have numbers in some of the labels then 10 would come before 2.  

It is important to understand we are actually sorting the Tree’s data provider, an XML object, instead of the Tree 

nodes directly.  My function sorts on only one attribute and it must be in every element of the XML object.&lt;/p&gt;&lt;br/&gt;

&lt;b&gt;Lower expectations and raise false hope&lt;/b&gt;&lt;br/&gt;

Still a lot of trees will look fine if the labels are all sorted the same way.  Also, I put the labels in an Array 

object to sort and allow you to pass in Array sorting arguments. So you may do descending, numeric, case insensitive and custom sorts.&lt;br/&gt;&lt;br/&gt;

If you are really desperate to sort on multiple types of labels, you could write a custom sort that would analyze the 

field and determine if it were alphanumeric, numeric, currency or a date before sorting.&lt;br/&gt;&lt;br/&gt;

There is another way to handle unusual situations. You could add an XML attribute to be used for sorting and another 

attribute for the label. The sorting attribute would never be seen, but would be used by my sorting function. This 

way you can sort numbers as alphanumeric by right aligning them and dates by first converting them to 

numbers.&lt;br/&gt;&lt;br/&gt;

Or you could wait because I know I will have to deal with this soon.&lt;br/&gt;&lt;br/&gt;

&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/XmlSort.jpg" width="374" height="277" alt="" border="0" align=""/&gt;&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;The example...&lt;/b&gt;&lt;br/&gt;

I have buttons for 5 different test sorts for the tree and the button click events are as follows:&lt;br/&gt;&lt;br/&gt;

Button "Sort Ascending" Click Event:
&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;sortXml( mvXml, "name" );
expandAllTreeNodes( Tree1 );&lt;/pre&gt;

Button "Sort Case Insensitive" Click Event:
&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;sortXml( mvXml, "name", Array.CASEINSENSITIVE );
expandAllTreeNodes( Tree1 );&lt;/pre&gt;

Button "Sort Descending" Click Event:
&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;sortXml( mvXml,
         "name",
         Array.CASEINSENSITIVE | Array.DESCENDING );
expandAllTreeNodes( Tree1 );&lt;/pre&gt;

Button "Sort Reverse" Click Event:
&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;sortXml( mvXml, "name", sortReverseText );
expandAllTreeNodes( Tree1 );&lt;/pre&gt;

Button "Sort Reverse Descending" Click Event:
&lt;pre style="margin-left:10px; font-size:90%; color:blue"&gt;sortXml( mvXml, 
         "name",
         sortReverseText,
         Array.DESCENDING );
expandAllTreeNodes( Tree1 );&lt;/pre&gt;

You can pass the Array sort options in the optional 3rd and 4th function arguments.  The last 2 click events use the 

custom sort function, "sortReverseText", which can be seen in the complete listing at the bottom of the 

post.&lt;br/&gt;&lt;br/&gt;

Note that it is necessary to expand the trees after each sort.  Of course, this only applies to the example.  In a 

real application you would want to restore the expanded states to their original settings.  This presents a whole 

different problem.&lt;br/&gt;&lt;br/&gt;

&lt;del&gt;&amp;nbsp;&amp;nbsp;Bug&amp;nbsp;&amp;nbsp;&lt;/del&gt; &lt;b&gt;Feature&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

The "name" argument refers to the name of the attribute to be sorted in each element. &lt;b&gt;This attribute must be in 

every element.  Otherwise the element, and descendents, will be lost after a sort.&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

Actually this could be a feature.  &lt;b&gt;Our product not only sorts, it automatically permanently filters out elements 

that don't have the required attribute.&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;The XML Sort Function&lt;/b&gt;&lt;br/&gt;

Here is a breakdown of the sort function, "sortXml", which is a recursive static function.&lt;br/&gt;&lt;br/&gt;

&lt;pre style="margin-left:10px; font-size:80%; color:blue"&gt;
 1 public static function sortXml
 2     ( avXml                :XML,
 3       avAttributeName      :String,
 4       avArraySortArgument0 :* = 0,
 5       avArraySortArgument1 :* = 0 )
 6     :void
 7 {
 8     var lvChildrenCount:int = avXml.children().length();
 9     
10     if( lvChildrenCount == 0 )
11         return;
12 
13     if( lvChildrenCount &amp;gt; 1 )
14     {
15         var lvAttributeValue:String;
16 
17         var lvArray:Array = new Array();
18         avXml.children().
19         (
20          lvAttributeValue = attribute( avAttributeName ),
21          lvArray.indexOf( lvAttributeValue ) == -1
22              ? lvArray.push( lvAttributeValue ) : null
23         );
24         
25         lvArray.sort
26         (
27             avArraySortArgument0,
28             avArraySortArgument1
29         );
30         
31         var lvXmlList:XMLList = new XMLList();
32         for each( lvAttributeValue in lvArray )
33         {
34             lvXmlList += avXml.children().
35             (
36                 attribute( avAttributeName )
37                 ==
38                 lvAttributeValue
39             );
40         } // for each
41         
42         avXml.setChildren( lvXmlList );
43         
44     } // if             
45 
46     for each( var lvXmlChild:XML in avXml.children() )
47     {
48         sortXml
49         (
50             lvXmlChild,
51             avAttributeName,
52             avArraySortArgument0,
53             avArraySortArgument1
54         );
55     } // for each
56     
57 } // sortXml
&lt;/pre&gt;

&lt;b&gt;Lines 17 - 29&lt;/b&gt;&lt;br/&gt;
I know you won't believe me, but I did not think I would ever want to use the exact code I used in the last example 

of 
&lt;a href="http://freerpad.blogspot.com/2007/06/more-getting-xml-elements-and.html"&gt;my preceding post&lt;/a&gt;.  The 

purpose is to get all unique attribute values into an Array and sort them.&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;Lines 31 - 40&lt;/b&gt;&lt;br/&gt;

The purpose of the code is to build a new XMLList object to contain all of the child elements in the sorted order.  

This code loops through each of the unique attribute values in the sorted Array, but the lines 34 thru 39 are a 

little more complicated.  These lines are one statement using E4X syntax.  Lines 36 thru 38 act a filter.  It returns 

all child elements where the attribute value is equal to the loop's current sorted attribute value.  It can return 

more than one element in the case where more than one element has the same attribute value.  The resulting XmlList 

variable, "lvXmlList", ends up containing the same child elements of the XML input argument "avXml".&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;Line 42&lt;/b&gt;&lt;br/&gt;

We are fortunate the XML class has the "setChildren" function.  With this function, the code replaces the existing 

children with the same, but sorted, elements in the XMLList object.&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;Lines 46 - 55&lt;/b&gt;&lt;br/&gt;

This is just the standard recursive stuff that calls this same function on all of the child elements so that their 

children, and so on, are sorted.  I tried to build an E4X statement to do the same thing.  Maybe a fresher mind, mine 

or yours can come up the code.&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;Complete Source Code for Example:&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;TreeSortExample.mxml&lt;/b&gt;
&lt;br/&gt;&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px solid #666666; 

border-left:1px solid #666666; border-right:1px solid #666666;
border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px" &gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="onCreationComplete()"
    &amp;gt;
    &amp;lt;mx:VBox
        height="100%"
        width="100%"
        x="50"
        y="5"
        &amp;gt;
        &amp;lt;mx:Panel
            width="90%"
            height="50%"
            horizontalAlign="center"
            title="Jim Freer's E4X Sorting for Trees"
            &amp;gt;
            &amp;lt;mx:HBox
                height="100%"
                width="100%"
                &amp;gt;
                &amp;lt;mx:VBox&amp;gt;
                    &amp;lt;mx:Button
                        label="Sort Ascending"
                        width="200"
                        click="onClickButtonSortTree1Ascending()"
                        /&amp;gt;
                    &amp;lt;mx:Button
                        label="Sort Case Insensitive"
                        width="200"
                        click="onClickButtonSortTree1CaseInsensitive()"
                        /&amp;gt;
                    &amp;lt;mx:Button
                        label="Sort Descending"
                        width="200"
                        click="onClickButtonSortTree1Descending()"
                        /&amp;gt;
                    &amp;lt;mx:Button
                        label="Sort Reverse"
                        width="200"
                        click="onClickButtonSortTree1Reverse()"
                        /&amp;gt;
                    &amp;lt;mx:Button
                        label="Sort Reverse Descending"
                        width="200"
                        click="onClickButtonSortTree1ReverseDescending()"
                        /&amp;gt;
                &amp;lt;/mx:VBox&amp;gt;
                &amp;lt;mx:Tree
                    id="Tree1"
                    height="100%"
                    width="100%"
                    dataProvider="{mvXml}"
                    labelField="@name"
                    /&amp;gt;
            &amp;lt;/mx:HBox&amp;gt;
        &amp;lt;/mx:Panel&amp;gt;
        &amp;lt;mx:Label
            text="*State capitals are in lowercase :) to demonstrate case insensitive sorting."
            /&amp;gt;

    &amp;lt;/mx:VBox&amp;gt;

    &amp;lt;mx:Script&amp;gt;
        &amp;lt;![CDATA[
        
        // ---------------------------------------------------------------------
        // Private Member Variables
        // ---------------------------------------------------------------------

        [Bindable]
        private var mvXml:XML =
            &amp;lt;Country name= "USA"&amp;gt;
              &amp;lt;State name="Texas"&amp;gt;
                &amp;lt;City name="Corpus Christi"/&amp;gt;
                &amp;lt;City name="austin"/&amp;gt;
                &amp;lt;City name="San Antonio"/&amp;gt;
              &amp;lt;/State&amp;gt;
              &amp;lt;State name="Michigan"&amp;gt;
                &amp;lt;City name="Ypsilanti"/&amp;gt;
                &amp;lt;City name="lansing"/&amp;gt;
                &amp;lt;City name="Ann Arbor"/&amp;gt;
                &amp;lt;City name="Kalamazoo"/&amp;gt;
                &amp;lt;City name="Allen Park"/&amp;gt;
              &amp;lt;/State&amp;gt;
            &amp;lt;/Country&amp;gt;;

        // ---------------------------------------------------------------------
        // expandAllTreeNodes
        // ---------------------------------------------------------------------
        
        private function expandAllTreeNodes
            ( avTree :Tree )
            :void
        {
            avTree.selectedIndex = 0;
            avTree.expandChildrenOf( avTree.selectedItem, true );
            
        } // expandAllTreeNodes     

        // ---------------------------------------------------------------------
        // onClickButtonSortTree1Ascending
        // ---------------------------------------------------------------------

        private function onClickButtonSortTree1Ascending
            ()
            :void
        {
            sortXml( mvXml, "name" );

            expandAllTreeNodes( Tree1 );
            
        } // onClickButtonSortTree1Ascending

        // ---------------------------------------------------------------------
        // onClickButtonSortTree1Descending
        // ---------------------------------------------------------------------
            
        private function onClickButtonSortTree1Descending
            ()
            :void
        {
            sortXml
                ( mvXml, "name", Array.CASEINSENSITIVE | Array.DESCENDING );

            expandAllTreeNodes( Tree1 );
            
        } // onClickButtonSortTree1Descending
        
        // ---------------------------------------------------------------------
        // onClickButtonSortTree1CaseInsensitive
        // ---------------------------------------------------------------------
        
        private function onClickButtonSortTree1CaseInsensitive
            ()
            :void
        {
            sortXml( mvXml, "name", Array.CASEINSENSITIVE );

            expandAllTreeNodes( Tree1 );
            
        } // onClickButtonSortTree1CaseInsensitive

        // ---------------------------------------------------------------------
        // onClickButtonSortTree1Reverse
        // ---------------------------------------------------------------------
            
        private function onClickButtonSortTree1Reverse
            ()
            :void
        {
            sortXml( mvXml, "name", sortReverseText );
            
            expandAllTreeNodes( Tree1 );
            
        } // onClickButtonSortTree1Reverse
        
        // ---------------------------------------------------------------------
        // onClickButtonSortTree1ReverseDescending
        // ---------------------------------------------------------------------
            
        private function onClickButtonSortTree1ReverseDescending
            ()
            :void
        {
            sortXml( mvXml, "name", sortReverseText, Array.DESCENDING );
            
            expandAllTreeNodes( Tree1 );
            
        } // onClickButtonSortTree1ReverseDescending
        
        // ---------------------------------------------------------------------
        // onCreationComplete
        // ---------------------------------------------------------------------

        private function onCreationComplete
            ()
            :void
        {
            expandAllTreeNodes( Tree1 );

        } // onCreationComplete
            
        // ---------------------------------------------------------------------
        // sortReverseText
        //
        // Reverses the strings before comparing.
        // For example, Kalamazoo is oozamalaK.
        // A lame example, but shows how to use a custom sort.
        // ---------------------------------------------------------------------

        private function sortReverseText
            ( avStringA :String,
              avStringB :String )
            :Number
        {
            var lvArray:Array;
            
            lvArray = avStringA.split( "" );
            lvArray = lvArray.reverse()
            var lvStringA:String = lvArray.join( "" );
            
            lvArray = avStringB.split( "" );
            lvArray = lvArray.reverse()
            var lvStringB:String = lvArray.join( "" );
            
            if( lvStringA &amp;gt; lvStringB )
            {
                return 1;
            } // if
            else if( lvStringA &amp;lt; lvStringB )
            {
                return -1;
            } // else if
            else
            {
                return 0;
            } // else
            
        } // sortReverseText

        // ---------------------------------------------------------------------
        // sortXml
        //
        // Warning: All elements in avXml must have an attribute with the name
        // in avAttributeName or the element will be deleted along with any
        // descendants.
        // ---------------------------------------------------------------------

        public static function sortXml
            ( avXml                :XML,
              avAttributeName      :String,
              avArraySortArgument0 :* = 0,
              avArraySortArgument1 :* = 0 )
            :void
        {
            var lvChildrenCount:int = avXml.children().length();
            
            if( lvChildrenCount == 0 )
                return;

            if( lvChildrenCount &amp;gt; 1 )
            {
                var lvAttributeValue:String;
    
                var lvArray:Array = new Array();
                avXml.children().
                (
                    lvAttributeValue = attribute( avAttributeName ),
                    lvArray.indexOf( lvAttributeValue ) == -1
                        ? lvArray.push( lvAttributeValue ) : null
                );
                
                lvArray.sort( avArraySortArgument0, avArraySortArgument1 )
                
                var lvXmlList:XMLList = new XMLList();
                for each( lvAttributeValue in lvArray )
                {
                    lvXmlList += avXml.children().
                    (
                        attribute( avAttributeName ) == lvAttributeValue
                    );
                } // for each
                
                avXml.setChildren( lvXmlList );
                
            } // if             

            for each( var lvXmlChild:XML in avXml.children() )
            {
                sortXml
                (
                    lvXmlChild,
                    avAttributeName,
                    avArraySortArgument0,
                    avArraySortArgument1
                );
            } // for each
            
        } // sortXml
        ]]&amp;gt;
    &amp;lt;/mx:Script&amp;gt;
        
&amp;lt;/mx:Application&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;

&lt;del&gt;&amp;nbsp;&amp;nbsp;Shameful&amp;nbsp;&amp;nbsp;&lt;/del&gt; &lt;b&gt;Shameless Solicitation&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

One more thing, I am looking for work (this time for money).  Any advice would be appreciated.
&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-3891268797767502714?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/3891268797767502714/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=3891268797767502714' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/3891268797767502714'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/3891268797767502714'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/06/actionscript-e4x-example-sorting.html' title='ActionScript E4X: Example Sorting Hierarchical XML Data for Tree Control'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-273015937635274080</id><published>2007-06-12T07:11:00.000-07:00</published><updated>2007-06-15T13:03:33.743-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><title type='text'>More, Getting XML Elements and Attributes VIA Variables with AS3 E4X</title><content type='html'>&lt;br/&gt;I found some useful information pertaining to my preceding post at ZEUSLABS &lt;a 

href="http://www.zeuslabs.us/2007/05/17/filter-xml-data-with-e4x-in-flash-part-2/"&gt; More XML 

filtering with E4X ActionScript 3&lt;/a&gt;.  The blog, by Josh Tynjala, has several useful tips.  His 

last example in that post is tackling the same problem with a few twists.&lt;br/&gt;&lt;br/&gt;

His example is certainly more in the spirit of E4X but I’m actually glad I built my solution 

anyway. Now I can compare the two approaches. I modified my code to use his technique as 

follows:&lt;br/&gt;&lt;br/&gt;


&lt;b&gt;(2) XmlElementAndAttributeViaVariables.as&lt;/b&gt;
&lt;br/&gt;&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px 

solid #666666; border-left:1px solid #666666; border-right:1px solid #666666;
border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px" &gt;package
{
 import flash.utils.getDefinitionByName;
 import flash.utils.describeType;

 public class XmlElementAndAttributeViaVariables
 {
  // ---------------------------------------------------------------------
  // Constructors
  // ---------------------------------------------------------------------
  
  public function XmlElementAndAttributeViaVariables
   ( avDescribeTypeName :String = "flash.text::TextField" )
  {
   var lvXml:XML = getDescribeType( avDescribeTypeName );
   
   testAndTrace( lvXml, "accessor", "type" );
   testAndTrace( lvXml, "method", "returnType" );
   
   //trace( lvXml.toXMLString() );
   
  } // Constructor
  
  // ---------------------------------------------------------------------
  // addUniqueValue
  // ---------------------------------------------------------------------
  
  private function addUniqueValue
   ( avAttributeValue :String,
     avArray          :Array )
   :Array
  {
   if( avArray.indexOf( avAttributeValue ) == -1 )
    avArray.push( avAttributeValue );
    
   return avArray;
   
  } // addUniqueValue
  
  // ---------------------------------------------------------------------
  // getDescribeType
  // ---------------------------------------------------------------------
  
  private function getDescribeType
   ( avClassName :String )
   :XML
  {
   return describeType( getDefinitionByName( avClassName ) );
   
  } // getDescribeType
  
  // ---------------------------------------------------------------------
  // getUniqueElementAttributeOfAllDescendants
  //
  // Returns a sorted string array of unique attribute values found in the
  // input object specified in the argument avXml for the element type with
  // the name given in the arguemnt avElementName.
  // The name of the attribute is specified in the argument
  // avAttributeName.
  // The function will use all of the named elements including nested
  // elements.
  // ---------------------------------------------------------------------
  
  public function getUniqueElementAttributeOfAllDescendants
   ( avXml           :XML,
     avElementName   :String,
     avAttributeName :String )
   :Array
  {
   var lvArray:Array = new Array();
   avXml.descendants( avElementName ).
   (
    lvArray = addUniqueValue( attribute( avAttributeName ), lvArray )
   );
   
   lvArray.sort();
   
   return lvArray;
   
  } // getUniqueElementAttributeOfAllDescendants
  
  // ---------------------------------------------------------------------
  // testAndTrace
  // ---------------------------------------------------------------------
  
  private function testAndTrace
   ( avXml           :XML,
     avElementName   :String,
     avAttributeName :String )
   :void
  {
   trace
   (
    "Element: " + avElementName + " Attribute: " + avAttributeName
   ); // trace
   
   var lvArray:Array =
    getUniqueElementAttributeOfAllDescendants
    (
     avXml,
     avElementName,
     avAttributeName
    )

   for( var lvIndex:int = 0; lvIndex &lt; lvArray.length; lvIndex++ )
    trace( lvIndex.toString() + " [" + lvArray[lvIndex] + "]" );
   
   trace( "\n" );
   
  } // testAndTrace
  
 } // class XmlElementAndAttributeViaVariables
 
} // package&lt;/pre&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;

The function, "getUniqueElementAttributeOfAllDescendants" was modified and I needed to add a new 

function, "addUniqueValue". At this point, I would probably stick with my original code. However, 

if I found out the approach shown in Josh’s example was faster I would jump ship.&lt;br/&gt;&lt;br/&gt;

One reason for sticking with mine is I like to make a line of code do only one thing.  It is an 

old programming style theory of mine.  I like to look at a line of code and grasp what it is doing 

without disassembling it.  I’m planning to make a post on my other blog, &lt;a 

href="http://anamericanprogrammer.blogspot.com/"&gt;An American Programmer&lt;/a&gt; in the future about 

this.  I feel it’s worthy of a posting because I‘ve gone through a few battles over the years on 

this and I think I am losing the war.  I’m afraid E4X is just another assault on my style.
This is from my application from the listing above and is the essence of Josh’s example:&lt;br/&gt;&lt;br/&gt;
avXml.descendants( avElementName ).&lt;br/&gt;
(&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvArray = addUniqueValue( attribute( avAttributeName ), lvArray )&lt;br/&gt;
);&lt;br/&gt;&lt;br/&gt;

The code, which is E4X syntax, is radically different from anything I’ve coded before and it kind 

of defies my programming style.  I like to keep my code short enough to be printed without line 

wrapping, but these 4 lines are one statement (with an embedded statement ).  I’ve broken the line 

with the dot dangling at then end.  I don’t like doing that because it’s easy to overlook the dot. 

 But that’s not my biggest concern.  The 3rd line is just really weird.  That statement is 

executed for every XML element derived from the first line.  First of all, I don’t think the use 

of the symbols (a dot followed by a statement enclosed in parentheses) is very good symbolism.  If 

the dot and parentheses were replaced with characters that better represented the true operation I 

might feel better about it.&lt;br/&gt;&lt;br/&gt;

The other reason why I like my original code is because I also have to add a function, 

“addUniqueValue” which is referenced in the 3rd line.  In all fairness, these are example 

applications.  In a real application breaking this into another function where things are more 

complex might not be an issue.  But in the example, the function is two lines of code that have to 

be broken out because you are limited in what you can put in the statement.  I’m not sure what the 

specifications say you can put in the statement because I have no ideal where this is documented.  

I tried various things to see if I could eliminate the function and do everything within the 

parentheses.  It won’t, for example, allow an “if” statement.  You can’t declare a variable with a 

“var”.  I keep getting compile errors indicating that the statement must begin with an 

identifier.&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;Breaking News!&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

&lt;i&gt;This is the problem I have with blogging.  When I am in the middle of writing a post I discover 

new things that contradict what I’ve just written.  This is a real problem because I don’t write 

that fast.&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;

Anyway you can forget about what I just wrote about having to add a function.  The discovery I’ve 

just made is that you are not limited to just one statement.  You can add multiple statements by 

separating them with commas.  (I swear I discovered this without any outside help.)  Apparently 

you are still stuck with starting a statement with an identifier so you can’t do an “if” 

statement.  But the “?:” statement begins with an identifier.&lt;br/&gt;&lt;br/&gt;

So the preceding example can be rewritten as follows:&lt;br/&gt;&lt;br/&gt;

var lvAttributeValue:String;&lt;br/&gt;
avXml.descendants( avElementName ).&lt;br/&gt;
(&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvAttributeValue = attribute( avAttributeName ),&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvArray.indexOf( lvAttributeValue ) == -1&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;? lvArray.push( lvAttributeValue ) : null&lt;br/&gt;
);&lt;br/&gt;&lt;br/&gt;

I still think my original solution is clearer and I think my last solution is the least clear.  

But E4X is probably going to be around for a while so I'm going to try to keep an open mind and 

explore how I can use it effectively.&lt;br/&gt;&lt;br/&gt;

This is the last version (at least in this post) of the entire class:&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;(3) XmlElementAndAttributeViaVariables.as&lt;/b&gt;&lt;br/&gt;
&lt;br/&gt;&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px 

solid #666666; border-left:1px solid #666666; border-right:1px solid #666666;
border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px" &gt;package
{
 import flash.utils.getDefinitionByName;
 import flash.utils.describeType;

 public class XmlElementAndAttributeViaVariables
 {
  // ---------------------------------------------------------------------
  // Constructors
  // ---------------------------------------------------------------------
  
  public function XmlElementAndAttributeViaVariables
   ( avDescribeTypeName :String = "flash.text::TextField" )
  {
   var lvXml:XML = getDescribeType( avDescribeTypeName );
   
   testAndTrace( lvXml, "accessor", "type" );
   testAndTrace( lvXml, "method", "returnType" );
   
   //trace( lvXml.toXMLString() );
   
  } // Constructor
  
  // ---------------------------------------------------------------------
  // getDescribeType
  // ---------------------------------------------------------------------
  
  private function getDescribeType
   ( avClassName :String )
   :XML
  {
   return describeType( getDefinitionByName( avClassName ) );
   
  } // getDescribeType
  
  // ---------------------------------------------------------------------
  // getUniqueElementAttributeOfAllDescendants
  //
  // Returns a sorted string array of unique attribute values found in the
  // input object specified in the argument avXml for the element type with
  // the name given in the arguemnt avElementName.
  // The name of the attribute is specified in the argument
  // avAttributeName.
  // The function will use all of the named elements including nested
  // elements.
  // ---------------------------------------------------------------------
  
  public function getUniqueElementAttributeOfAllDescendants
   ( avXml           :XML,
     avElementName   :String,
     avAttributeName :String )
   :Array
  {
   var lvArray:Array = new Array();
   var lvAttributeValue:String;
   avXml.descendants( avElementName ).
   (
    lvAttributeValue = attribute( avAttributeName ),
    lvArray.indexOf( lvAttributeValue ) == -1 ? lvArray.push( lvAttributeValue ) : null
   );
   
   lvArray.sort();
   
   return lvArray;
   
  } // getUniqueElementAttributeOfAllDescendants
  
  // ---------------------------------------------------------------------
  // testAndTrace
  // ---------------------------------------------------------------------
  
  private function testAndTrace
   ( avXml           :XML,
     avElementName   :String,
     avAttributeName :String )
   :void
  {
   trace
   (
    "Element: " + avElementName + " Attribute: " + avAttributeName
   ); // trace
   
   var lvArray:Array =
    getUniqueElementAttributeOfAllDescendants
    (
     avXml,
     avElementName,
     avAttributeName
    )

   for( var lvIndex:int = 0; lvIndex &lt; lvArray.length; lvIndex++ )
    trace( lvIndex.toString() + " [" + lvArray[lvIndex] + "]" );
   
   trace( "\n" );
   
  } // testAndTrace
  
 } // class XmlElementAndAttributeViaVariables
 
} // package&lt;/pre&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-273015937635274080?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/273015937635274080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=273015937635274080' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/273015937635274080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/273015937635274080'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/06/more-getting-xml-elements-and.html' title='More, Getting XML Elements and Attributes VIA Variables with AS3 E4X'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-7951394604809042502</id><published>2007-06-10T07:21:00.000-07:00</published><updated>2007-06-11T04:43:55.726-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='E4X'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><title type='text'>Getting XML Elements and Attributes VIA Variables with AS3 E4X</title><content type='html'>&lt;br/&gt;For some reason this ended up being a lot harder for me than it should have been.  The code ended up being a little more traditional than you would think when using the exotic syntax of ActionScript’s E4X but it is still very concise.&lt;br/&gt;&lt;br/&gt;

I think part of my problem was that I was expecting to need the exotic part of the E4X syntax.  E4X is very hard to describe.  I know authors, with much better writing skills than mine, have tried but so far I haven’t seen a great explanation.  Most everyone relies on showing examples which I end up copying and then trial and error editing to fit my needs.&lt;br/&gt;&lt;br/&gt;

Unfortunately, the following is typical of the examples:&lt;br/&gt;&lt;br/&gt;

var lvXmlList:XMLList = lvXml..accessor;&lt;br/&gt;&lt;br/&gt;

Variable lvXml’s class type is XML in this example.  The code would return an XMLList object containing all of the &amp;lt;accessor/&amp;gt; elements including those nested inside of other elements.  The nesting functionality comes from the powerful double dot operator.  The example is neat, particularly when you are giving a one hour presentation on “What’s New in ActionScript 3”.  It will “wow” the audience.  However, over time you may find this type of coding to be too inflexible.&lt;br/&gt;&lt;br/&gt;

In my case, I want some code where “accessor” can be variable and at the same time I want to retrieve the value of an attribute of the elements which is also variable.  In particular (for my example listing below)  I want the same code to get elements &amp;lt;accessor/&amp;gt; or &amp;lt;method/&amp;gt; and their corresponding attributes “type” and “returnType” or any other element, attribute combination.&lt;br/&gt;&lt;br/&gt;

&amp;lt;accessor name=”x” type=”Number”/&amp;gt;&lt;br/&gt;
&amp;lt;method name=”border” returnType=”Boolean”/&amp;gt;&lt;br/&gt;&lt;br/&gt;


The key to doing this is to make use of two functions, “descendants(elementName)” and “attribute(attributeName)” of the class XML.  Now the previous code:&lt;br/&gt;&lt;br/&gt;

var lvXmlList:XMLList = lvXml..accessor;&lt;br/&gt;&lt;br/&gt;

can be redone as:&lt;br/&gt;&lt;br/&gt;

var lvElementName:String = “accessor”;&lt;br/&gt;
var lvXmlList:XMLList = lvXml.descendants( lvElementName );&lt;br/&gt;&lt;br/&gt;

You can then loop through each of the  “accessor” elements as follows:&lt;br/&gt;&lt;br/&gt;

var lvAttributeName:String = “type”;&lt;br/&gt;
for each( var lvXmlElement:XML in lvXmlList )&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace( lvXmlElement.attribute( lvAttributeName ) );&lt;br/&gt;

&lt;br/&gt;

I have built an example class.  The class's function,
'getUniqueElementAttributeOfAllDescendants()'
shows how the two XML functions are used.&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;XmlElementAndAttributeViaVariables.as&lt;/b&gt;
&lt;br/&gt;&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px solid #666666; border-left:1px solid #666666; border-right:1px solid #666666;
border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px" &gt;package
{
 import flash.utils.getDefinitionByName;
 import flash.utils.describeType;

 public class XmlElementAndAttributeViaVariables
 {
  // ---------------------------------------------------------------------
  // Constructors
  // ---------------------------------------------------------------------
  
  public function XmlElementAndAttributeViaVariables
   ( avDescribeTypeName :String = "flash.text::TextField" )
  {
   var lvXml:XML = getDescribeType( avDescribeTypeName );
   
   testAndTrace( lvXml, "accessor", "type" );
   testAndTrace( lvXml, "method", "returnType" );
   
   //trace( lvXml.toXMLString() );
   
  } // Constructor
  
  // ---------------------------------------------------------------------
  // getDescribeType
  // ---------------------------------------------------------------------
  
  private function getDescribeType
   ( avClassName :String )
   :XML
  {
   return describeType( getDefinitionByName( avClassName ) );
   
  } // getDescribeType
  
  // ---------------------------------------------------------------------
  // getUniqueElementAttributeOfAllDescendants
  //
  // Returns a sorted string array of unique attribute values found in the
  // input object specified in the argument avXml for the element type with
  // the name given in the arguemnt avElementName.
  // The name of the attribute is specified in the argument
  // avAttributeName.
  // The function will use all of the named elements including nested
  // elements.
  // ---------------------------------------------------------------------
  
  public function getUniqueElementAttributeOfAllDescendants
   ( avXml           :XML,
     avElementName   :String,
     avAttributeName :String )
   :Array
  {
   var lvArray:Array = new Array();
   
   for each( var lvXmlAccessor:XML
              in avXml.descendants(avElementName) )
   {
    var lvString:String
     = lvXmlAccessor.attribute( avAttributeName );
    
    if( lvArray.indexOf( lvString ) == -1 )
     lvArray.push( lvString );
     
   } // for each
   
   lvArray.sort();
   
   return lvArray;
   
  } // getUniqueElementAttributeOfAllDescendants
  
  // ---------------------------------------------------------------------
  // testAndTrace
  // ---------------------------------------------------------------------
  
  private function testAndTrace
   ( avXml           :XML,
     avElementName   :String,
     avAttributeName :String )
   :void
  {
   trace
   (
    "Element: " + avElementName + " Attribute: " + avAttributeName
   ); // trace
   
   var lvArray:Array =
    getUniqueElementAttributeOfAllDescendants
    (
     avXml,
     avElementName,
     avAttributeName
    )

   for( var lvIndex:int = 0; lvIndex &lt; lvArray.length; lvIndex++ )
    trace( lvIndex.toString() + " [" + lvArray[lvIndex] + "]" );
   
   trace( "\n" );
   
  } // testAndTrace
  
 } // class XmlElementAndAttributeViaVariables
 
} // package
&lt;/pre&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;

The example class deals with the built-in reflection function “flash.utils.describeType”.  This function returns an XML description of  an ActionScript object.  By default, I use the XML description of a TextField object as input,  What I want are all of the different types returned by the TextField class’s properties (accessor) and functions (method).  When the example class is instantiated in the debug mode the following trace output is generated:&lt;br/&gt;&lt;br/&gt;

Element: accessor Attribute: type&lt;br/&gt;
&lt;b&gt;0 [*]&lt;/b&gt;&lt;br/&gt;
1 [Array]&lt;br/&gt;
2 [Boolean]&lt;br/&gt;
3 [Number]&lt;br/&gt;
4 [Object]&lt;br/&gt;
5 [String]&lt;br/&gt;
6 [flash.accessibility::AccessibilityImplementation]&lt;br/&gt;
7 [flash.accessibility::AccessibilityProperties]&lt;br/&gt;
8 [flash.display::DisplayObject]&lt;br/&gt;
9 [flash.display::DisplayObjectContainer]&lt;br/&gt;
10 [flash.display::LoaderInfo]&lt;br/&gt;
11 [flash.display::Stage]&lt;br/&gt;
12 [flash.geom::Rectangle]&lt;br/&gt;
13 [flash.geom::Transform]&lt;br/&gt;
14 [flash.text::StyleSheet]&lt;br/&gt;
15 [flash.text::TextFormat]&lt;br/&gt;
16 [flash.ui::ContextMenu]&lt;br/&gt;
17 [int]&lt;br/&gt;
18 [uint]&lt;br/&gt;&lt;br/&gt;


Element: method Attribute: returnType&lt;br/&gt;
0 [Array]&lt;br/&gt;
1 [Boolean]&lt;br/&gt;
2 [String]&lt;br/&gt;
3 [flash.display::DisplayObject]&lt;br/&gt;
4 [flash.geom::Point]&lt;br/&gt;
5 [flash.geom::Rectangle]&lt;br/&gt;
6 [flash.text::TextFormat]&lt;br/&gt;
7 [flash.text::TextLineMetrics]&lt;br/&gt;
8 [int]&lt;br/&gt;
9 [void]&lt;br/&gt;&lt;br/&gt;

I have edited the resulting XML that is returned when running&lt;br/&gt;&lt;br/&gt;

trace( describeType( getDefinitionByName( “flash.text::TextField” ) ) )&lt;br/&gt;&lt;br/&gt;

which is shown in the listing below.&lt;br/&gt;&lt;br/&gt;

I have reduced it down to elements and attributes pertaining to this post.  I also reordered the elements.  The nesting ability of the descendants function can be seen within the first four lines.  The accessor “prototype” has a “type” attribute of “*” which is the only accessor with that type and is included in the trace list above (&lt;b&gt;0 [*]&lt;/b&gt;).  But the “prototype” accessor’s parent is &amp;lt;type/&amp;gt; whereas all other accessors are the child of &amp;lt;factory/&amp;gt;&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;describeType( getDefinitionByName( “flash.text::TextField” ) )&lt;/b&gt;
&lt;br/&gt;&lt;br/&gt;&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px solid #666666; border-left:1px solid #666666; border-right:1px solid #666666;
border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px" &gt;&amp;lt;type name="flash.text::TextField" base="Class" isDynamic="true" isFinal="true" isStatic="true"&amp;gt;

  &amp;lt;accessor name="prototype"                     type="*"/&amp;gt;

  &amp;lt;factory type="flash.text::TextField"&amp;gt;

    &amp;lt;accessor name="filters"                     type="Array"/&amp;gt;
    
    &amp;lt;accessor name="alwaysShowSelection"         type="Boolean"/&amp;gt;
    &amp;lt;accessor name="background"                  type="Boolean"/&amp;gt;
    &amp;lt;accessor name="border"                      type="Boolean"/&amp;gt;
    &amp;lt;accessor name="cacheAsBitmap"               type="Boolean"/&amp;gt;
    &amp;lt;accessor name="condenseWhite"               type="Boolean"/&amp;gt;
    &amp;lt;accessor name="displayAsPassword"           type="Boolean"/&amp;gt;
    &amp;lt;accessor name="doubleClickEnabled"          type="Boolean"/&amp;gt;
    &amp;lt;accessor name="embedFonts"                  type="Boolean"/&amp;gt;
    &amp;lt;accessor name="mouseEnabled"                type="Boolean"/&amp;gt;
    &amp;lt;accessor name="mouseWheelEnabled"           type="Boolean"/&amp;gt;
    &amp;lt;accessor name="multiline"                   type="Boolean"/&amp;gt;
    &amp;lt;accessor name="selectable"                  type="Boolean"/&amp;gt;
    &amp;lt;accessor name="useRichTextClipboard"        type="Boolean"/&amp;gt;
    &amp;lt;accessor name="tabEnabled"                  type="Boolean"/&amp;gt;
    &amp;lt;accessor name="visible"                     type="Boolean"/&amp;gt;
    &amp;lt;accessor name="wordWrap"                    type="Boolean"/&amp;gt;
    
    &amp;lt;accessor name="alpha"                       type="Number"/&amp;gt;
    &amp;lt;accessor name="height"                      type="Number"/&amp;gt;
    &amp;lt;accessor name="mouseX"                      type="Number"/&amp;gt;
    &amp;lt;accessor name="mouseY"                      type="Number"/&amp;gt;
    &amp;lt;accessor name="rotation"                    type="Number"/&amp;gt;
    &amp;lt;accessor name="scaleX"                      type="Number"/&amp;gt;
    &amp;lt;accessor name="scaleY"                      type="Number"/&amp;gt;
    &amp;lt;accessor name="sharpness"                   type="Number"/&amp;gt;
    &amp;lt;accessor name="textHeight"                  type="Number"/&amp;gt;
    &amp;lt;accessor name="textWidth"                   type="Number"/&amp;gt;
    &amp;lt;accessor name="thickness"                   type="Number"/&amp;gt;
    &amp;lt;accessor name="x"                           type="Number"/&amp;gt;
    &amp;lt;accessor name="y"                           type="Number"/&amp;gt;
    &amp;lt;accessor name="width"                       type="Number"/&amp;gt;

    &amp;lt;accessor name="antiAliasType"               type="String"/&amp;gt;
    &amp;lt;accessor name="autoSize"                    type="String"/&amp;gt;
    &amp;lt;accessor name="blendMode"                   type="String"/&amp;gt;
    &amp;lt;accessor name="gridFitType"                 type="String"/&amp;gt;
    &amp;lt;accessor name="htmlText"                    type="String"/&amp;gt;
    &amp;lt;accessor name="name"                        type="String"/&amp;gt;
    &amp;lt;accessor name="restrict"      type="String"/&amp;gt;
    &amp;lt;accessor name="selectedText"                type="String" /&amp;gt;
    &amp;lt;accessor name="text"                        type="String"/&amp;gt;
    &amp;lt;accessor name="type"                        type="String"/&amp;gt;
    
    &amp;lt;accessor name="focusRect"                   type="Object"/&amp;gt;
    &amp;lt;accessor name="opaqueBackground"            type="Object"/&amp;gt;

    &amp;lt;accessor name="accessibilityImplementation" type="flash.accessibility::AccessibilityImplementation"/&amp;gt;
    
    &amp;lt;accessor name="accessibilityProperties"     type="flash.accessibility::AccessibilityProperties"/&amp;gt;
    
    &amp;lt;accessor name="mask"                        type="flash.display::DisplayObject"/&amp;gt;
    &amp;lt;accessor name="root"                        type="flash.display::DisplayObject"/&amp;gt;
    
    &amp;lt;accessor name="parent"                      type="flash.display::DisplayObjectContainer"/&amp;gt;
    
    &amp;lt;accessor name="loaderInfo"                  type="flash.display::LoaderInfo"/&amp;gt;
    
    &amp;lt;accessor name="stage"                       type="flash.display::Stage"/&amp;gt;

    &amp;lt;accessor name="scale9Grid"                  type="flash.geom::Rectangle"/&amp;gt;
    &amp;lt;accessor name="scrollRect"                  type="flash.geom::Rectangle"/&amp;gt;
    
    &amp;lt;accessor name="transform"                   type="flash.geom::Transform"/&amp;gt;
    
    &amp;lt;accessor name="styleSheet"                  type="flash.text::StyleSheet"/&amp;gt;
    
    &amp;lt;accessor name="defaultTextFormat"           type="flash.text::TextFormat"/&amp;gt;

    &amp;lt;accessor name="contextMenu"                 type="flash.ui::ContextMenu"/&amp;gt;
    
    &amp;lt;accessor name="bottomScrollV"               type="int"/&amp;gt;
    &amp;lt;accessor name="caretIndex"                  type="int"/&amp;gt;
    &amp;lt;accessor name="length"                      type="int"/&amp;gt;
    &amp;lt;accessor name="maxChars"                    type="int"/&amp;gt;
    &amp;lt;accessor name="maxScrollH"                  type="int"/&amp;gt;
    &amp;lt;accessor name="maxScrollV"                  type="int"/&amp;gt;
    &amp;lt;accessor name="numLines"                    type="int"/&amp;gt;
    &amp;lt;accessor name="scrollH"                     type="int"/&amp;gt;
    &amp;lt;accessor name="scrollV"                     type="int"/&amp;gt;
    &amp;lt;accessor name="selectionBeginIndex"         type="int"/&amp;gt;
    &amp;lt;accessor name="selectionEndIndex"           type="int"/&amp;gt;
    &amp;lt;accessor name="tabIndex"                    type="int"/&amp;gt;
    
    &amp;lt;accessor name="backgroundColor"             type="uint"/&amp;gt;
    &amp;lt;accessor name="borderColor"                 type="uint"/&amp;gt;
    &amp;lt;accessor name="textColor"                   type="uint"/&amp;gt;

    &amp;lt;method name="getTextRuns"                   returnType="Array"/&amp;gt;
    
    &amp;lt;method name="dispatchEvent"                 returnType="Boolean"/&amp;gt;
    &amp;lt;method name="hasEventListener"              returnType="Boolean"/&amp;gt;
    &amp;lt;method name="hitTestObject"                 returnType="Boolean"/&amp;gt;
    &amp;lt;method name="hitTestPoint"                  returnType="Boolean"/&amp;gt;
    &amp;lt;method name="willTrigger"                   returnType="Boolean"/&amp;gt;
    
    &amp;lt;method name="getLineText"                   returnType="String"/&amp;gt;
    &amp;lt;method name="getRawText"                    returnType="String"/&amp;gt;
    &amp;lt;method name="getXMLText"                    returnType="String"/&amp;gt;
    &amp;lt;method name="toString"                      returnType="String"/&amp;gt;

    &amp;lt;method name="getImageReference"             returnType="flash.display::DisplayObject"/&amp;gt;

    &amp;lt;method name="localToGlobal"                 returnType="flash.geom::Point"/&amp;gt;
    &amp;lt;method name="globalToLocal"                 returnType="flash.geom::Point"/&amp;gt;

    &amp;lt;method name="getBounds"                     returnType="flash.geom::Rectangle"/&amp;gt;
    &amp;lt;method name="getCharBoundaries"             returnType="flash.geom::Rectangle"/&amp;gt;
    &amp;lt;method name="getRect"                       returnType="flash.geom::Rectangle"/&amp;gt;

    &amp;lt;method name="getTextFormat"                 returnType="flash.text::TextFormat"/&amp;gt;

    &amp;lt;method name="getLineMetrics"                returnType="flash.text::TextLineMetrics"/&amp;gt;

    &amp;lt;method name="getCharIndexAtPoint"           returnType="int"/&amp;gt;
    &amp;lt;method name="getFirstCharInParagraph"       returnType="int"/&amp;gt;
    &amp;lt;method name="getLineIndexAtPoint"           returnType="int"/&amp;gt;
    &amp;lt;method name="getLineIndexOfChar"            returnType="int"/&amp;gt;
    &amp;lt;method name="getLineLength"                 returnType="int"/&amp;gt;
    &amp;lt;method name="getLineOffset"                 returnType="int"/&amp;gt;
    &amp;lt;method name="getParagraphLength"            returnType="int"/&amp;gt;
    
    &amp;lt;method name="addEventListener"              returnType="void"/&amp;gt;
    &amp;lt;method name="appendText"                    returnType="void"/&amp;gt;
    &amp;lt;method name="insertXMLText"                 returnType="void"/&amp;gt;
    &amp;lt;method name="removeEventListener"           returnType="void"/&amp;gt;
    &amp;lt;method name="replaceSelectedText"           returnType="void"/&amp;gt;
    &amp;lt;method name="replaceText"                   returnType="void"/&amp;gt;
    &amp;lt;method name="setSelection"                  returnType="void"/&amp;gt;
    &amp;lt;method name="setTextFormat"                 returnType="void"/&amp;gt;
    
  &amp;lt;/factory&amp;gt;
&amp;lt;/type&amp;gt;&lt;/pre&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;


After reading what I have just written, it seems too trivial to post.  But I was unable to find an example on the internet on how to do this.&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-7951394604809042502?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/7951394604809042502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=7951394604809042502' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/7951394604809042502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/7951394604809042502'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/06/getting-xml-elements-and-attributes-via.html' title='Getting XML Elements and Attributes VIA Variables with AS3 E4X'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-3698252839539168494</id><published>2007-05-18T14:42:00.000-07:00</published><updated>2007-05-18T14:43:50.407-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RIA Flex Flash Actionscript SWF'/><title type='text'>Migrating State Picker drop-down list to AS3</title><content type='html'>&lt;br/&gt;
I was hoping to be able to post regularly and at the same time have some meat in the content. An early goal was to narrate my experiences 

converting my 2 custom &lt;a href="http://en.wikipedia.org/wiki/Drop-down_list"&gt;drop-down lists&lt;/a&gt; to ActionScript 3 (AS3).  I knew it would 

be a challenge.  To be perfectly honest, I almost gave up back when I was trying to build them with ActionScript 2 (AS2).
&lt;br/&gt;&lt;br/&gt;

I built a State Picker and a Date Picker control with Flash MX2004 and later updated them with Flash 8.  The controls are built from 

scratch using only TextFields and MovieClips.  The State Picker is shown below and the AS2 Rich Internet Application (RIA) demo the 

controls were written for is linked below also.  The Date Picker can be seen from the demo as well (click on “Shipping Info” in the RIA’s 

menu).

&lt;br/&gt;&lt;br/&gt;
&lt;img alt="" src="http://www.elegantfloraldesigns.us/blogstuff/StatePicker.jpg" border="0" /&gt;
&lt;br/&gt;
&lt;a href="http://www.elegantfloraldesigns.us/efdtest.html"&gt;
State Picker in RIA Demo in Shipping Info Form&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;a href="http://www.elegantfloraldesigns.us/efdtest.html"&gt;
&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/EFD.jpg" width="250" height="209" alt="" border="0" align=""/&gt;
&lt;br/&gt;My RIA Demo
&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
I have played around with Flex 2’s MXML but up until a few days ago I really haven’t done anything serious with AS3. The bottom line is 

that it has taken me longer to figure out how to do this with AS3 and thus a larger gap in my posting than I had hoped.  I was hoping to 

post the source code early in the narrative but I know now that this won’t happen.  I do have a rough version running and I will try to 

post the .swf file shortly.

&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-3698252839539168494?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/3698252839539168494/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=3698252839539168494' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/3698252839539168494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/3698252839539168494'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/05/migrating-state-picker-drop-down-list.html' title='Migrating State Picker drop-down list to AS3'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-2878461971263102101</id><published>2007-05-02T12:23:00.001-07:00</published><updated>2007-05-02T12:23:56.468-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RIA Flex Flash Actionscript SWF'/><title type='text'>SWF Size: ActionScript 3 versus ActionScript</title><content type='html'>I was concerned I wasn’t going to get compact SWF files from ActionScript 3 (AS3) like I was getting from ActionScript 2 (AS2).  But after running some simple tests, I am now thinking AS3 will not be a problem.&lt;br/&gt;&lt;br/&gt;

Unfortunately, I’m still disappointed with the large SWF size from MXML projects.  However, I still plan to use Flex 2 with MXML to develop my back-end tools to take advantage of its rapid development qualities.  At the same time I will pick up some practical experience with MXML.  Maybe after seeing MXML in action, I might become less resistant to using it in my Rich Internet Applications (RIA).&lt;br/&gt;&lt;br/&gt;

SWF files are compressed and this can cause confusion when it comes to analyzing and comparing size.  For example, when I refactor my AS2 source code to be more efficient, I sometimes find it results in a larger size.  Simply changing the order of things in your code can affect the size because of the compression.  Fortunately, I found Flash 8 AS2 SWF files end up amazingly small regardless of my coding style.&lt;br/&gt;&lt;br/&gt;

My tests are crude and leave plenty of room for misinterpretation and argument.  Nonetheless, I have concluded AS3 files grow incrementally at about the same pace even though they start out initially about 500 bytes larger.&lt;br/&gt;&lt;br/&gt;

I wrote test code in AS2 and AS3 to build 2 TextFields. I compared the resulting SWF file size by compiling 3 different versions of each.  The first, everything was commented out.  The second, 1 TestField was created.  Finally the third, 2 TextFields were created.&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;AS2&lt;/b&gt;
&lt;div style="BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #666666 1px solid; FONT-SIZE: 78%; OVERFLOW: scroll; BORDER-LEFT: #666666 1px solid; WIDTH: 400px; BORDER-BOTTOM: #666666 1px solid; HEIGHT: 300px"&gt;
&lt;pre style="MARGIN-LEFT: 4px; WIDTH: 700px"&gt;var mvTextField1:TextField = createTextField
(
  "T1",
 getNextHighestDepth(),
 0,
 0,
 200,
 20
);
mvTextField1.text = "T1";

var mvTextField2:TextField = createTextField
(
  "T2",
 getNextHighestDepth(),
 0,
 20,
 200,
 20
);
mvTextField2.text = "T2";
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;

&lt;b&gt;AS3&lt;/b&gt;
&lt;div style="BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #666666 1px solid; FONT-SIZE: 78%; OVERFLOW: scroll; BORDER-LEFT: #666666 1px solid; WIDTH: 400px; BORDER-BOTTOM: #666666 1px solid; HEIGHT: 300px"&gt;
&lt;pre style="MARGIN-LEFT: 4px; WIDTH: 700px"&gt;package
{
 import flash.display.Sprite;
 import flash.text.*;

 public class ActionScriptSizeTest extends Sprite
 {
  public function ActionScriptSizeTest()
  {
   var lvTextField1:TextField = new TextField();
   lvTextField1.x = 0;
   lvTextField1.y = 0;
   lvTextField1.width = 200;
   lvTextField1.height = 20;
   lvTextField1.text = "T1"
   addChild( lvTextField1 );

   var lvTextField2:TextField = new TextField();
   lvTextField2.x = 0;
   lvTextField2.y = 20;
   lvTextField2.width = 200;
   lvTextField2.height = 20;
   lvTextField2.text = "T2"
   addChild( lvTextField2 );

  } // Constructor

 } // public class

} // package
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;

&lt;table border="2"&gt;
&lt;caption&gt;&lt;b&gt;AS2 / AS3 SWF Size Comparison, bytes&lt;/b&gt;&lt;/caption&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;th&gt;Test&lt;/th&gt;
&lt;th&gt;AS2 &lt;/th&gt;
&lt;th&gt;AS3 &lt;/th&gt;
&lt;th&gt;Increase&lt;/th&gt;
&lt;/tr&gt;
&lt;tbody&gt;

&lt;tr&gt;
&lt;th&gt;&lt;p align="left"&gt;No code&lt;/p&gt;&lt;/th&gt;
&lt;td&gt;&lt;p align="right"&gt;36&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p align="right"&gt;566&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p align="right"&gt;530&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;th&gt;&lt;p align="left"&gt;1 TextField&lt;/p&gt;&lt;/th&gt;
&lt;td&gt;&lt;p align="right"&gt;144&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p align="right"&gt;667&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p align="right"&gt;523&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;th&gt;&lt;p align="left"&gt;2 TextFields &lt;/p&gt;&lt;/th&gt;
&lt;td&gt;&lt;p align="right"&gt;172&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p align="right"&gt;694&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;&lt;p align="right"&gt;522&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;/tbody&gt;
&lt;/table&gt;
&lt;br/&gt;&lt;br/&gt;

The results actually show AS3 to be better incrementally than AS2 but the differences are too small to be significant.&amp;nbsp;&amp;nbsp;Remember, the compression confuses everything.&amp;nbsp;&amp;nbsp;I was worried that bringing in a TextField might require some extra library code.&amp;nbsp;&amp;nbsp;It turns out adding a TextField adds only a little more than 100 bytes for both ActionScripts.&lt;br/&gt;&lt;br/&gt;

The whole coding strategy changes when you migrate to ActionScript 3, so I can’t say if the equivalent program would be smaller or larger.&amp;nbsp;&amp;nbsp;I’m never going to write the same application again.&amp;nbsp;&amp;nbsp;At the very least I would write it with more features.&amp;nbsp;&amp;nbsp;So I’ll never know.
&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-2878461971263102101?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/2878461971263102101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=2878461971263102101' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/2878461971263102101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/2878461971263102101'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/05/swf-size-actionscript-3-versus.html' title='SWF Size: ActionScript 3 versus ActionScript'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-4343277086419572593</id><published>2007-04-23T06:45:00.000-07:00</published><updated>2007-05-02T12:22:15.698-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SWF'/><category scheme='http://www.blogger.com/atom/ns#' term='ActionScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Programming Style'/><title type='text'>ActionScript 3 and Programming Style</title><content type='html'>I’ve began commenting with dashes to separate functions in the 60’s.&amp;nbsp;&amp;nbsp;(See the ActionScript 3 code below.)&amp;nbsp;&amp;nbsp;Initially I used asterisks but they required 3 holes in a punch card whereas dashes required only 1.&amp;nbsp;&amp;nbsp;A card filled with 3 rows of holes would sometimes collapse in the reader.&amp;nbsp;&amp;nbsp;Style has beauty and function but it also has history and structural integrity.&lt;br/&gt;&lt;br/&gt;

Before starting this blog I picked up a new book, &lt;a href="http://www.clearblogging.com/"&gt;“clear blogging”&lt;/a&gt; by Bob Walsh published by Apress.&amp;nbsp;&amp;nbsp;I like it so far but I haven’t finished reading it.&amp;nbsp;&amp;nbsp;I felt I needed some hands on experience at the same time.&amp;nbsp;&amp;nbsp;However, I’m going to start exercising one of his points and that is to blog about topics I love.&amp;nbsp;&amp;nbsp;One topic I love is “programming style”.&lt;br/&gt;&lt;br/&gt;

This is the ActionScript 3 code I used to measure the SWF file size in my previous post:&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;EFD1.as&lt;/b&gt;
&lt;br/&gt;&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px solid #666666; border-left:1px solid #666666; border-right:1px solid #666666;
border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px" &gt;package
{
    import flash.display.Sprite;
    import display.Header;

    public class EFD1 extends Sprite
    {
    /*  --------------------------------------------------------------------
        Constructor
        -------------------------------------------------------------------- */
           
        public function EFD1
            ()
        {
            var lvHeader:Header = new Header
            (
                200,
                [0x8A39B9, 0x9D5BBF],
                "Shop by Category"
            );
            
            addChild( lvHeader );
            
        } // Constructor
        
    } // class EFD1
    
} // package

&lt;/pre&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;Header.as&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;
&lt;div style="width:400px; height:300px; overflow:scroll; border-width:thick;border-top:1px solid #666666;  border-left:1px solid #666666; border-right:1px solid #666666; border-bottom:1px solid #666666; font-size:78%"&gt;
&lt;pre style="margin-left:4px; width:700px"&gt;package display
{
    import flash.display.*;
    import flash.text.TextField;
    import flash.geom.*

    public class Header extends Sprite
    {
    /*  --------------------------------------------------------------------
        Private Static Variables
        -------------------------------------------------------------------- */
        
        // Programmers looking at my code:
        // Please don't do what I've done here.  That is, don't declare these
        // as static variables.  I did this when I was testing how much memory
        // is used.  Although this technique works and is expedient, it will
        // end up biting you later on.
        private static var svCorner     :Number = 5;
        private static var svHeight     :Number = 18.0;
        private static var svIndent     :Number = 5;
        private static var svMargin     :Number = 2;
        private static var svTextColor  :uint = 0xFFFFFF;
    
    /*  --------------------------------------------------------------------
        Private Member Variables
        -------------------------------------------------------------------- */
        
        private var mvTextField :TextField;
        
    /*  --------------------------------------------------------------------
        Constructor
        -------------------------------------------------------------------- */
    
        public function Header
            ( avWidth  :Number,
              avColors :Array,
              avText   :String = "" )
        {
            super();            
            
            var lvWidth:Number = avWidth - svMargin - svMargin;

            //Add Gradient Header           
            var lvMatrix:Matrix = new Matrix();
            lvMatrix.createGradientBox( lvWidth, svHeight, Math.PI * .5, 0, 0);
            
            graphics.beginGradientFill
            (
                GradientType.LINEAR,
                avColors,
                [1, 1],
                [0x0, 0xFF],
                lvMatrix,
                SpreadMethod.PAD
            );  
            
            graphics.drawRoundRect( svMargin, svMargin, lvWidth, svHeight, svCorner );

            // Add TextField            
            mvTextField = new TextField();
            mvTextField.x = svMargin + svIndent;
            mvTextField.y = svMargin;
            mvTextField.width = lvWidth - svIndent - svIndent;
            mvTextField.height = svHeight;
            mvTextField.textColor = svTextColor;
            mvTextField.selectable = false;
            setText( avText );
            addChild( mvTextField );
            
        } // Constructor
        
    /*  --------------------------------------------------------------------
        setText
        -------------------------------------------------------------------- */
        
        public function setText
            ( avText :String )
            :void
        {
            mvTextField.text = avText;
            
        } // setText
    
    } // class Header
    
} // package display

&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Code produces &lt;b&gt;EFD1.swf&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

&lt;img height="157" alt="" src="http://www.elegantfloraldesigns.us/blogstuff/header.jpg" width="351" border="0" /&gt;&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-4343277086419572593?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/4343277086419572593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=4343277086419572593' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/4343277086419572593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/4343277086419572593'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/04/flex-2-and-programming-style.html' title='ActionScript 3 and Programming Style'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-7589374850761763981</id><published>2007-04-22T10:51:00.000-07:00</published><updated>2007-05-02T12:21:36.559-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RIA Flex Flash Actionscript SWF'/><title type='text'>Flex SWF files are big, but I like the productivity</title><content type='html'>&lt;a href="http://www.elegantfloraldesigns.us/efdtest.html"&gt;
&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/EFD.jpg" width="250" height="209" alt="" border="0" align=""/&gt;
&lt;br/&gt;My RIA Demo
&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;

My first Rich Internet Application (RIA) was created with Flash MX2004. I then converted it to Flash 8.&amp;nbsp;&amp;nbsp;Now I want to build new RIA’s, so I bought Flex Builder 2 which will hopefully help me be more productive.&amp;nbsp;&amp;nbsp;I have been excited about the new way of doing things.&amp;nbsp;&amp;nbsp;I think the biggest advantage will come from the addition of the Sprite object and other more focused visual objects instead of having to use heavy weighted MovieClip’s for everything.&amp;nbsp;&amp;nbsp;Also, all of these visual objects, including the MovieClip, are now created and added to the Stage in a familiar object oriented manner.&lt;br/&gt;&lt;br/&gt;


One of the hardest things about using Flash to build RIA’s was learning how to take the animation out of the application.&amp;nbsp;&amp;nbsp;It was hard to use the documentation and the help available from the internet because it was usually described in terms of frames.&amp;nbsp;&amp;nbsp;Eventually, I was able to weed through it.  I ended up using only 2 or 3 frames to get my application started and otherwise never used a timeline.&amp;nbsp;&amp;nbsp;It looks like ActionScript 3 can be used like a traditional development language and I like that.&lt;br/&gt;&lt;br/&gt;

We are told Flex 2 applications will run faster due to improved player performance and that never hurts.&amp;nbsp;&amp;nbsp;I really don’t have a problem with my first RIA running too slow after the initial startup and I must have hundreds of little MovieClips that need to be created.&amp;nbsp;&amp;nbsp;I’m even happy with the startup speed but anything less than instantaneous startup could always use improvement.&amp;nbsp;&amp;nbsp;I’m going to put more effort into the startup speed in my next application.&amp;nbsp;&amp;nbsp;I’m thinking I can really make a lot of improvements here especially since I won’t have the overhead of MovieClips and will gain from the reported player improvements.&lt;br/&gt;&lt;br/&gt;

I got the impression from somewhere in the hype that the compiled code would be more compact but I’m skeptical.&amp;nbsp;&amp;nbsp;My Flash 8 application is currently 68,089 bytes long.&amp;nbsp;&amp;nbsp;I was always amazed at how small it was.&amp;nbsp;&amp;nbsp;I started programming in the early days when program size dominated the architecture.&amp;nbsp;&amp;nbsp;I am probably more attuned to size than most programmers because it is usually not an issue today.&amp;nbsp;&amp;nbsp;Of course there is no doubt that the larger the file, the slower the download.&amp;nbsp;&amp;nbsp;Also, the ISP allows a limited number of bytes per month before surcharges kick in.&lt;br/&gt;&lt;br/&gt;

I became disappointed immediately after installing Flex Builder 2.&amp;nbsp;&amp;nbsp;I created an MXML project and compiled it with no code added.&amp;nbsp;&amp;nbsp;The size of the SWF file was 125,617 bytes.&amp;nbsp;&amp;nbsp;That was nearly twice as big as my working Flash 8 application.&amp;nbsp;&amp;nbsp;Then I built an ActionScript 3 project with no extra code.&amp;nbsp;&amp;nbsp;The file size was 568 bytes compared to 36 bytes for a Flash 8 file.&lt;br/&gt;&lt;br/&gt;

The difference between the empty ActionScript 3 and ActionScript 2 SWF files is not a great concern.&amp;nbsp;&amp;nbsp;(That is, unless you need an SWF file that does nothing.)&amp;nbsp;&amp;nbsp;I’m not even sure I would be totally unhappy if I could write the equivalent functionality into an MXML application and it took 68,000 additional bytes on top of the base 125,000 bytes.&amp;nbsp;&amp;nbsp;The start up could actually be faster because of improved performance even though the download would be slower.&lt;br/&gt;&lt;br/&gt;

Unfortunately, it really does appear that the code grows quickly when using Flex Builder 2 to build either ActionScript 3 or MXML projects.&amp;nbsp;&amp;nbsp;I wrote some ActionScript 3 code to create a Sprite with a rounded rectangular header with gradient fill and a TextField for a title.&amp;nbsp;&amp;nbsp;The size of the SWF is 1179.  That means it took 611 bytes for this function along with some test code.&amp;nbsp;&amp;nbsp;Now the source code is relatively concise compared to doing this with Flash 8 and the source code is clean and clear which is wonderful.&amp;nbsp;&amp;nbsp;I haven’t taken the time to build a Flash 8 file to do the same thing.&amp;nbsp;&amp;nbsp;There is a fair amount of code to do just the drawing of a rounded rectangle in ActionScript 2.&amp;nbsp;&amp;nbsp;But I don’t think it would take 611 bytes to do it.&lt;br/&gt;&lt;br/&gt;

&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/header.jpg" width="351" height="157" alt="" border="0" align=""&gt;&lt;br/&gt;&lt;br/&gt;

I tried to duplicate a small part of my existing application with MXML and it grew to 283,867 (or 158,250 bytes more) and I admit I didn’t even figure how to do everything with the MXML.&amp;nbsp;&amp;nbsp;Because of this, I’m not sure I’m going to commit to MXML at this point.  This is disappointing for at least two reasons. First, I didn’t need to buy Flex Builder 2 to build pure ActionScript 3 applications.&amp;nbsp;&amp;nbsp;Second, my hope of increasing productivity was due partly to being able to use the nice set of GUI controls Flex provides.&lt;br/&gt;&lt;br/&gt;

At this point, I have a gut feeling that the SWF files are going to be significantly bigger even if I don’t use MXML  It may be that I’m not configuring the project correctly.&amp;nbsp;&amp;nbsp;It may be that the end result is still better than before because of speed of execution will compensate for the slower download time.&amp;nbsp;&amp;nbsp;I have seen enough to know that I will be able to develop projects faster and the resulting source code will be easier to maintain but I sure would like to hear some comment about the file sizes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-7589374850761763981?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/7589374850761763981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=7589374850761763981' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/7589374850761763981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/7589374850761763981'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/04/flex-swf-files-are-big-but-i-like.html' title='Flex SWF files are big, but I like the productivity'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-674134548655639627.post-1731028196011219195</id><published>2007-04-20T14:17:00.000-07:00</published><updated>2007-05-02T12:20:58.611-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RIA Flash Actionscript'/><title type='text'>Getting Started with RIA</title><content type='html'>This is my first attempt at blogging.&amp;nbsp;&amp;nbsp;I’m finding the hardest part of getting started is choosing the focus of the blog.&amp;nbsp;&amp;nbsp;I’ve decided initially it will be about Rich Internet Applications (RIA).&amp;nbsp;&amp;nbsp;I don’t have any RIA’s up and running and have never even created a traditional website so I’m guessing the blog’s framework will be a journal.&lt;br/&gt;&lt;br/&gt;

I have been programming since 1966 but I really have done very little work recently due partly to health problems.&amp;nbsp;&amp;nbsp;Actually I have kept active during the last two years; just haven’t made any money.&amp;nbsp;&amp;nbsp;Now I’m trying to reboot my career.&amp;nbsp;&amp;nbsp;I’ve changed directions umpteen times in the last 40 years and actually enjoy the transitions.&amp;nbsp;&amp;nbsp;I love programming, but I have to admit in recent years I’ve had to take what I can get to survive rather than do what I want to do.&amp;nbsp;&amp;nbsp;I’m hope developing RIA’s will be fun.&amp;nbsp;&amp;nbsp;I have resisted doing web applications because I feel that the customer has to settle for the limitations of HTML and the browser.&lt;br/&gt;&lt;br/&gt;

Although I don’t have any RIA sites up and running I do have experience writing a Flash application that I’m going to use for discussion.&amp;nbsp;&amp;nbsp;The application was written originally with Flash MX2004 and more recently updated to Flash 8.&amp;nbsp;&amp;nbsp;My goal is to move to Flex or perhaps just Actionscript 3 and build something similar but maybe for a different type of business.&amp;nbsp;&amp;nbsp;My son has suggested a web site for an auto dealer because of his recent experience buying a car.&lt;br/&gt;&lt;br/&gt;

The application I wrote was for my daughter-in-law’s hobby of doing custom floral arrangements.&amp;nbsp;&amp;nbsp;She was often asked when promoting her hobby if she had a website.&amp;nbsp;&amp;nbsp;Since my son was a developer of corporate web sites he started to build one for her, but they could never agree on how it should look.&amp;nbsp;&amp;nbsp;Finally they found a template for a florist website that they both liked.&amp;nbsp;&amp;nbsp;Since I wasn’t working he asked me to look at it.&amp;nbsp;&amp;nbsp;He wanted me to change the text and set it up so that they could insert pictures of her arrangements in it.&lt;br/&gt;&lt;br/&gt;

Well, I looked at it and I just couldn’t believe you could make money selling something like that template.&amp;nbsp;&amp;nbsp;For example, the template split parts of a picture into more than one table cell to make it line up.&amp;nbsp;&amp;nbsp;The few pages they had didn’t match her needs and they were missing a lot what she did need.&amp;nbsp;&amp;nbsp;But it did look pretty good.&lt;br/&gt;&lt;br/&gt;

I told them I would try using Flash which I had previously used to write some small educational applications.&amp;nbsp;&amp;nbsp;It took a lot longer to write than I thought it would and I will discuss some of my experiences in the future.&amp;nbsp;&amp;nbsp;But to make an already long story somewhat shorter, she really hasn’t pursued the hobby since and it has been sitting there waiting to put in a few unaddressed details.&amp;nbsp;&amp;nbsp;The link to the applications is:&lt;br/&gt;&lt;br/&gt;

&lt;a href="http://www.elegantfloraldesigns.us/efdtest.html"&gt;
&lt;img src="http://www.elegantfloraldesigns.us/blogstuff/EFD.jpg" width="250" height="209" alt="" border="0" align=""/&gt;
&lt;br/&gt;My RIA Demo
&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;

Keep in mind this is not a running business and the products are not real.&amp;nbsp;&amp;nbsp;I will touch on the details of the application as I go along but I think the most interesting things about it are that it is all written from scratch graphically except for the Actionscript TextField object and it is less than 70k in size.&amp;nbsp;&amp;nbsp;There is also very little demand on the server.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/674134548655639627-1731028196011219195?l=freerpad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://freerpad.blogspot.com/feeds/1731028196011219195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=674134548655639627&amp;postID=1731028196011219195' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/1731028196011219195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/674134548655639627/posts/default/1731028196011219195'/><link rel='alternate' type='text/html' href='http://freerpad.blogspot.com/2007/04/getting-started-with-ria.html' title='Getting Started with RIA'/><author><name>Jim Freer</name><uri>http://www.blogger.com/profile/04675896663697865109</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
