2010-07-14 6 views
1

J'ai un document XML chargé. J'ai créé une liste horizontale et j'ai référencé la collection de tableaux en tant que fournisseur de données. Mais ce que je dois faire maintenant, c'est extraire les données de cela.Affichage de nœuds XML à partir d'une collection de tableaux

J'ai 3 noeuds/variables. Ils sont id, titre, vignette.

Mais quand je vais passer à travers les données: {videos.title} Flex Builder me donne l'erreur - « L'accès des vidéos de propriété non définie »

Maintenant, je sais très bien qu'il existe, comme quand je mets le dataProvider { vidéos} il tire à travers les données sans problème.

Mon code est le suivant:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      minWidth="800" minHeight="600" 
      initialize="channelList.send(),videoList.send()" 
      pageTitle="Video List" 
      width="100%" height="100%" backgroundColor="0x0000" xmlns:local="*"> 

<fx:Style> 
    @namespace s "library://ns.adobe.com/flex/spark"; 
    @namespace mx "library://ns.adobe.com/flex/mx"; 
</fx:Style> 

<fx:Script> 
    <![CDATA[ 
     import mx.collections.ArrayCollection; 
     import mx.messaging.Channel; 
     import mx.rpc.events.FaultEvent; 
     import mx.rpc.events.ResultEvent; 

     import spark.skins.spark.DefaultComplexItemRenderer; 
     import spark.skins.spark.DefaultItemRenderer; 

     import videoObjects.Videoinfo; 

     // Set the Videos XML to an Array Collection 

     var videos:ArrayCollection = new ArrayCollection(); 


     // Event Handler 

     protected function videoRetrieval_resultHandler(event:ResultEvent):void { 

      var videoData:ArrayCollection = event.result.videos.video; 

      var viddata:Videoinfo; 

      for each (var vid:Object in videoData) 
      { 
       viddata = new Videoinfo(); 

       viddata.id = vid.id; 
       viddata.title = vid.title; 
       viddata.thumbnail = vid.thumbnail; 
       videos.addItem(viddata); 
      } 
     } 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 

    <s:HTTPService id="channelList" 
        url="http://www.spriing.dev/videolist/channelinfo.php" 
        showBusyCursor="true"> 
    </s:HTTPService> 

    <s:HTTPService id="videoList" 
        url="http://www.spriing.dev/videolist/videolist.php" 
        showBusyCursor="true" 
        result="videoRetrieval_resultHandler(event)"> 
    </s:HTTPService> 

</fx:Declarations> 

    <!-- Set Background Image --> 
     <mx:Image source="{channelList.lastResult.channels.channel.background_image}" width="100%" height="100%" /> 
    <!-- End Background Image --> 

    <!-- Top Nav/Site Logo etc.. --> 
    <s:Group> 
     <mx:Image source="file:/Users/stuartblackett/Sites/videolist/img/pokerstars.png" x="14" y="9" /> 
    </s:Group> 

    <!-- Group Channel Information --> 
    <s:Group width="100%" height="100%" x="10" y="10" styleName="channelInfo"> 
     <s:Label text="{channelList.lastResult.channels.channel.name}" x="19" y="77" width="331" color="#FFFFFF" fontSize="14"/> 
     <s:Label text="{channelList.lastResult.channels.channel.description}" x="19" y="106" width="331" color="#FFFFFF" height="70"/> 
     <s:Label text="{channelList.lastResult.channels.channel.breadcrumb}" x="20" y="61" color="#FFFFFF"/> 
     <mx:Image source="{channelList.lastResult.channels.channel.logo}" x="199" y="78" /> 

      <s:Group width="100%" height="100%"> 
       <!-- Group Video Data --> 

       <s:Label text="FULL EPISODES" color="#FFFFFF" x="493" y="501" height="21"/> 
       <mx:HorizontalList id="videoArea" 
            rowHeight="160" 
            columnWidth="180" 
            columnCount="5" 
            x="489" y="527" 
            dataProvider="{videos}" 
            labelField="title" 
            width="653"> 
         <mx:itemRenderer> 
          <fx:Component> 
           <mx:VBox> 
            <mx:Image source="img/"/> 
            <mx:Label text="{videos.title}"/> 
           </mx:VBox> 
          </fx:Component> 
         </mx:itemRenderer> 
        </mx:HorizontalList> 

       <s:VideoPlayer y="63" width="649" height="415" x="493"/> 

      </s:Group> 

    </s:Group> 

</s:Application> 

Comment puis-je obtenir le noeud XML: titre et bien sûr la vignette aussi?

Répondre

1

changement <mx:Label text="{videos.title}"/> à

<mx:Label text="{data.title}"/> 

Pour afficher l'image, faire

<mx:Image source="img/{data.thumbnail}"/> 

Vous essayez d'accéder videos d'un moteur de rendu (à partir de la balise <mx:component>) élément drop-in - vous ne pouvez pas le faire directement. Le rendu d'élément peut accéder aux propriétés de son document externe via la propriété outerDocument. Ainsi outerDocument.videos.title fonctionnerait - ou pas. Dans ce cas, cela ne fonctionnera pas comme vous le souhaitez - vous voulez que chaque élément de la liste affiche le titre correspondant. Le outerDocument.videos.title vous donnera simplement une liste XML des titres - utilisez la propriété data pour accéder à l'élément actuel.

+0

Ahh, Merci pour cette Amarghosh data.title fonctionne un régal. Dans HorizontalList, je l'ai défini sur dataProvider = {videos} il semble avoir dupliqué les données dans la liste. Puis-je empêcher cela? – StuBlackett

+0

@Stu Je ne comprends pas ce que vous entendez par duplication - pouvez-vous élaborer? – Amarghosh

+0

Il semblait que la collection de tableaux se répétait. J'ai donc eu une énorme boîte HorizontalList. Il s'avère que les images et le texte étaient juste un peu trop gros pour les contraintes que j'ai dites. Merci beaucoup pour votre aide – StuBlackett

Questions connexes