1 Reply Latest reply on Apr 27, 2008 7:31 PM by peterent

    Trouble using XML data inside horizontal list

    Jaguar280
      Hey everyone,

      im trying to use xml code as the data provider for a horizontal list with pictures. i tried to read up on some of the xml documentation for flex but my project is still not working correctly. first, i tried to use the httpservice method to access my external xml file but everytime the program ran it would say that it cannot access the local file. any thoughts? anyways, i got frustrated with the error and instead i tried to just code some xml directly into the project. then i tried to assign some data in the xml to a variable and use that for the icon property of each object (code below). i am not getting any errors but its not rendering the pictures. what could be the problem???? THANK YOU SO MUCH!!!! still trying to learn flex.. its very interesting :-)

      p.s. i removed the states and transitions part to make the code smaller..

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="600" backgroundGradientAlphas="[1.0, 1.0]"
      backgroundGradientColors="[#FFFFFF, #FFFFFF]" initialize="initializeHandler();">


      <mx:Script>
      <![CDATA[
      import mx.events.ListEvent;
      import mx.controls.Alert;

      [Bindable]
      [Embed(source="../assets/event1.png")]
      public var event1:Class;

      [Bindable]
      [Embed(source="../assets/event2.png")]
      public var event2:Class;

      [Bindable]
      [Embed(source="../assets/event3.png")]
      public var event3:Class;

      [Bindable]
      [Embed(source="../assets/event4.png")]
      public var event4:Class;

      [Bindable]
      [Embed(source="../assets/event5.png")]
      public var event5:Class;

      [Bindable]
      [Embed(source="../assets/event6.png")]
      public var event6:Class;

      [Bindable]
      private var myEvents:XML =
      <events>
      <images>
      <image>event1.png</image>
      <image>event2.png</image>
      <image>event3.png</image>
      </images>
      </events>

      private function initializeHandler():void {
      object1.icon = myEvents.events.images.image[0];
      object2.icon = myEvents.events.images.image[1];
      }

      private function itemClicked(event:ListEvent):void {
      var icon:Object = this.PosterSelect.selectedItem.data;
      var url:String = ' http://www.google.com/' + icon + ".png";
      // Alert.show(url);
      navigateToURL(new URLRequest(url), '_blank');
      }


      ]]>
      </mx:Script>


      <mx:Panel id="FirstPanel" title="Upcoming Events: Click on the flyers below to enlarge."
      paddingTop="0" paddingBottom="0" paddingLeft="0" paddingRight="0" borderColor="#006BFC" themeColor="#009DFF" cornerRadius="20" alpha="1.0">

      <!--<mx:Label width="100%" color="blue"
      text="Click on one of the images to enlarge."/>-->

      <mx:HorizontalList id="PosterSelect" height="352" columnCount="3" columnWidth="200" width="580"
      rollOverColor="#ff3344" themeColor="#DC240B" itemClick="itemClicked(event)">
      <mx:dataProvider>
      <mx:Array>
      <mx:Object id="object1" label="March 12, 2008&#13;Detroit, MI" data="events"/>
      <mx:Object id="object2" label="March 12, 2008&#13;Detroit, MI" data="events"/>
      <mx:Object label="March 12, 2008&#13;Detroit, MI" icon="{event3}" data="events"/>
      <mx:Object label="March 12, 2008&#13;Detroit, MI" icon="{event4}" data="events"/>
      <mx:Object label="March 12, 2008&#13;Detroit, MI" icon="{event5}" data="events"/>
      </mx:Array>
      </mx:dataProvider>
      </mx:HorizontalList>
      <mx:ControlBar>
      <mx:LinkButton id="BottomButton" label="Click here to change view!"/>
      <mx:Spacer width="100%" id="spacer1"/>
      <mx:Button label="Change View" id="TiledButton" click="currentState='Tiled'"/>
      </mx:ControlBar>
      </mx:Panel>

      </mx:Application>
        • 1. Re: Trouble using XML data inside horizontal list
          peterent Level 2
          Your HorizontalList needs an itemRenderer to display al the fields. At best, the list will display just one of the fields.

          As for the first problem, the Flash Player cannot read local files. If you had placed your data with your application code in Flex Builder, when the app was compiled Flex Builder would have copied the data along with the SWF into the bin directory (or debug-bin) and you could have read it that was as the URL would make the Flash Player think the file was coming from the same domain as the SWF.