A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: E4x

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    E4x

    I could use a hand figuring out how to access this XML data with e4x
    I'm not having alot of success so far

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    <channel>
    
    <title>Yahoo! Weather - Marietta, GA</title>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Marietta__GA/*http://weather.yahoo.com/forecast/30062_f.html</link>
    <description>Yahoo! Weather for Marietta, GA</description>
    <language>en-us</language>
    <lastBuildDate>Wed, 13 May 2009 9:08 am EDT</lastBuildDate>
    <ttl>60</ttl>
    <yweather:location city="Marietta" region="GA"   country="US"/>
    
    <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
    <yweather:wind chill="61"   direction="90"   speed="7" />
    <yweather:atmosphere humidity="77"  visibility="10"  pressure="30.24"  rising="0" />
    <yweather:astronomy sunrise="6:38 am"   sunset="8:31 pm"/>
    <image>
    <title>Yahoo! Weather</title>
    <width>142</width>
    <height>18</height>
    <link>http://weather.yahoo.com</link>
    <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
    </image>
    <item>
    
    <title>Conditions for Marietta, GA at 9:08 am EDT</title>
    <geo:lat>33.96</geo:lat>
    <geo:long>-84.53</geo:long>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Marietta__GA/*http://weather.yahoo.com/forecast/30062_f.html</link>
    <pubDate>Wed, 13 May 2009 9:08 am EDT</pubDate>
    <yweather:condition  text="Light Rain"  code="11"  temp="61"  date="Wed, 13 May 2009 9:08 am EDT" />
    <description><![CDATA[
    <img src="http://l.yimg.com/a/i/us/we/52/11.gif"/><br />
    <b>Current Conditions:</b><br />
    Light Rain, 61 F<BR />
    <BR /><b>Forecast:</b><BR />
    Wed - Mostly Cloudy. High: 74 Low: 61<br />
    Thu - Partly Cloudy. High: 81 Low: 61<br />
    <br />
    <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Marietta__GA/*http://weather.yahoo.com/forecast/USGA0353_f.html">Full Forecast at Yahoo! Weather</a><BR/>
    (provided by The Weather Channel)<br/>
    ]]></description>
    <yweather:forecast day="Wed" date="13 May 2009" low="61" high="74" text="Mostly Cloudy" code="28" />
    <yweather:forecast day="Thu" date="14 May 2009" low="61" high="81" text="Partly Cloudy" code="30" />
    <guid isPermaLink="false">30062_2009_05_13_9_08_EDT</guid>
    </item>
    
    </channel>
    </rss><!-- api2.weather.sp1.yahoo.com compressed/chunked Wed May 13 06:24:40 PDT 2009 -->

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok so I figured it out mostly..... Here is a great example of why E4X is very useful in parsing XML data....

    put a html text field on the stage and add the following code in AS3

    PHP Code:
    var loc="30062";//Default Location

    var xmlLoader:URLLoader = new URLLoader();
    var 
    xmlData:XML = new XML();
     
    xmlLoader.addEventListener(Event.COMPLETELoadXML);

    xmlLoader.load(new URLRequest("http://weather.yahooapis.com/forecastrss?p="+loc));
     
    function 
    LoadXML(e:Event):void {
       
    xmlData = new XML(e.target.data);
       
    txt2.htmlText=xmlData.channel.item.title;
       
    txt2.htmlText+=xmlData.channel.item.description;
       
    debug.text=txt2.htmlText


  3. #3
    Member
    Join Date
    Dec 2005
    Location
    Utah
    Posts
    98
    Very cool. E4X is good ju-ju.

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center