Apr
03

Parsing xml in Flex - The case of tag names with a dash

I am a fan of json.
I use it extensively but sometimes I am forced to use xml. A pretty well know way to parse xml in Flex and Adobe air is the following:

  var xml:XML = new XML(“<data><tag>content</tag></data>”);
  private function parse():void {
	 for each (var t:XML in xml.children()) {
		trace(“tag name: “+t.name()+” tag content “+t.text());
	}
  }

Sometimes you are not the one who establishes tag names, e.g. xml comes from a webservice and you have to use it as it is. In developing Posty I had to parse xml coming from a microblogging service, Tumblr. An sample xml returned by tumblr is the following.

<post id=”30451729″ …>
	  <regular-body>Text of my post…</regular-body>
</post>

Notice there is a dash in some tag name. To render data you parse the xml and extract relevant data. Adopting the same approach explained above, to retrieve the content of a tag you’d write:

  for each (var x:XML in xml.posts.post) {
    trace(“my regular body is “+ x.regular-body);
  }

You will not be able to run this code. The compiler will say: access of undefined property body. What! I can’t parse xml with dashed tag names? No you can’t. More evidence from here[link]. The solution is to exploit a different syntax, which allows to access data in a dashed-name tag:

  for each (var x:XML in xml.posts.post) {
    trace(“my regular body is “+ x.child(“regular-body”));
  }

The compiler will be happy and your xml will be parsed successfully.

Mar
20

Adobe Air already on iphone (sort of)

I started developing in Flash, doing websites. I then moved to Flash mobile (before the introduction of flite) and developed a mobile guide for a research project. When Flex was presented I didn’t dive into it, because I was busy with other projects and languages. When Adobe Air (introduced as Apollo) was released I started experimenting again. When I heard of the iphone I thought: “This is the platform of the future!”. But I felt disappointed when Steve confessed he didn’t like Flash on the iphone. Now I am simply thinking:

  • isn’t iphone running Safari? Yes
  • isn’t Safari based on webkit? Yes
  • aren’t Adobe Air application partly running on webkit? Yes, if developed in javascript/html.

So? I think it is not far the moment that ad Adobe Air application will run on the iPhone.

Mar
19

Flash Player on iPhone

Tags: flash, iphone

What a great news! Looks like Adobe is already implementing a flash player for the iphone. I was having a look at the iPhone sdk and was fascinated by its features. But this is a good news. Steve was lamenting there is a gap between the Flash player and its lite version. Let’s hope the gap will be filled soon! I was tempted to port Posty to the iphone. Maybe I don’t need to to that and I can focus on new features.  
Update: check here and here.

top