Log In  
  Getting Started  
----------------------------------------

Resources

 

Code Anatomy

Take an interactive tour of the application logic. You can toggle between the running application and the underlying source code as you walk through the Flickr simple RIA application.

Click the following image to start the Code Anatomy application.

previous page next page
previous page next page

Out of curiosity, why does Namespace point to search.yahoo.com/mrss/? Where can I get more info on using Namespace?

Also, I don't fully understand data.media::thumbnail.@url, can someone break this down for me?

Posted by Tony Eckert at Mar 10, 2008 06:43Updated by Tony Eckert

Namespace is a class inthe Flash API. You can get more info here: http://livedocs.adobe.com/flex/3/langref/Namespace.html

I've emailed the author to see if he can comment on your other question, but it looks like e4x syntax to me, which is just a way to access properties and attributes of XML objects.

If you browse to http://search.yahoo.com/mrss/ you will see that this is a "Media specification" and is "An RSS module.."

the line:   

private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");  

declares a variable named media of type Namespace then instantiates it by invoking the constructor passing in a URI pointing to the RSS spec. So we have an Actionscript Namespace object.

The source property of the Image control is being databound as follows:   

 source="{data.media::thumbnail.@url}"

Flex will interpret the curly brace syntax, and apply its result to the source property of the Image control and the thumbnail image is displayed.

Let's breakdown the various parts of the contents of the curly braces:

  • the "data.media" part: remember that this component (MXML file) is an itemRenderer for a TileList. ItemRenderer has a 'data' property (of type Object) that holds whatever this component is supposed to render.  If you set a breakpoint in the code and examine the 'data' Object you will see a bunch of XML delivered from Flickr that conforms to the RSS spec outlined in the URL above. This particular line is of interest in this case:
      
    <media:thumbnail url="http://farm3.static.flickr.com/blahblahblah.jpg" height="75" width="75"/>
  • the :: part: this is Namespace access. So we are using the media Namespace and accessing something in that Namespace  (the thumbnail element's url attribute in the XML contained in the data Object).
  • the thumbnail.@url part: this is E4X. We are accessing the url attribute of the thumbnail element

So Flex evaluates the whole deal and applies it to the source property of the Image Control which grabs the bits from Flickr for the image and displays it.

Hi,all.

    Firstly,Thanks for the sample.However,I got a stange problem.The following is the discription:

    In the file "FlickrThumbnail",the following code  I copy from the "code anatomy".

     <?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="125" height="125" horizontalAlign="center" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
    <mx:Script>
        <![CDATA[
        private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");
        ]]>
    </mx:Script>
    <mx:Image width="75" height="75" source="

Unknown macro: {data.media}
"/>
    <mx:Text width="100" text="
Unknown macro: {data.media}
"/>
</mx:VBox>

    The code doesn't work,but when I modify some parts it works.the new following code can work:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="125" height="125" horizontalAlign="center" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
    <mx:Script>
        <![CDATA[
            private var mediaNs:Namespace = new Namespace("http://search.yahoo.com/mrss/");
        ]]>       
    </mx:Script>
    <mx:Image width="75" height="75" source="

Unknown macro: {data.thumbnail.url}
"/>
    <mx:Text width="100" text="
Unknown macro: {data.credit}
"/>   
</mx:VBox>

 so, can any body tell me the reason. I am a fresh man in Flex. This problem brothers me for one night. Thanks very much.

I cant's understand why the NameSpace varible named media doesn't work. If any body can explain or resolve this problem for me, please email me.My email is: handy.wang@finalist.cn.

I will invite you to china , drink some coffee and do some else happiness.

I don't understand the use of Namespace here

The sample code don't work for me, and i've simply wrote this, wich works fine.

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
    width="200" height="200"
    horizontalAlign="center"
    paddingBottom="5"
    paddingLeft="5"
    paddingRight="5"
    paddingTop="5"
    >
   
    <mx:Image width="100" height="100" source ="

Unknown macro: {data.thumbnail.url}
"/>
    <mx:Text width="100" text="
Unknown macro: {data.credit}
"/>
</mx:VBox>

I am running this app behind a firewall which blocks this external site. So clicking search button doesn't do anything. Is it possible to catch the exception as we do in other programming languages?

It works well when I am running this at another location.

Added by Mark Nichoson , last edited by Randy Nielsen on Apr 28, 2009  (view change)
Labels: 
(None)

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators