2009-03-30 11 views
0

作成完了時にxmlによってTileListが作成されました。選択したアイテムのイメージをイメージコンポーネントのソースに渡したいと思います。Flex 3 XMLフィードTileList選択されたアイテムを別のコンポーネントに渡します。

これは、メインアプリケーションである:私はImageコンポーネントのソースの異なるものを試してみましたが、何も私はちょうど4疑問符を置くように働いていない

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" backgroundColor="#FFFFFF"> 
<mx:ArrayCollection id="theImages"></mx:ArrayCollection> 
<mx:Model id="items" source="items.xml" /> 
<mx:Script> 
    <![CDATA[ 
     import ItemListObject; 
     public function initList():void 
     { 
      for each (var node:Object in items.image) { 
      var temp:ItemListObject = new ItemListObject(); 
      temp.strThumbnail = node.strThumbnail; 
      temp.title = node.title; 
      theImages.addItem(temp); 
      } 
} 
    ]]> 
</mx:Script> 
<mx:XML source="adjectives.xml" id="adjectivesXML"/> 
    <mx:Canvas x="20" y="20"> 
     <mx:Image 
      id="item" 
      source="????" 
      autoLoad="true" 
      width="500" 
      height="500" 
      scaleContent="true"/> 
    </mx:Canvas> 
    <mx:TileList id="imageTileList" 
     itemRenderer="CustomItemRenderer" 
     dataProvider="{theImages}" 
     width="400" 
     height="400" 
     columnCount="2" 
     creationComplete="initList();"/> 
    </mx:Application> 

。 ItemsListObject.as

package 
{ 
[Bindable] 
public class ItemListObject extends Object 
{ 
    public function ItemListObject() { 
    super(); 
    } 

    public var title:String = new String(); 
    public var strThumbnail:String = new String(); 
} 
} 

これは非常にラフな例ですが、私一度

<?xml version="1.0" encoding="utf-8"?> 
<items> 
<image id="1"> 
    <title>Image 1</title> 
    <strThumbnail>1.jpg</strThumbnail> 
</image> 
<image id="2"> 
    <title>Image 2</title> 
    <strThumbnail>2.jpg</strThumbnail> 
</image> 
<image id="3"> 
    <title>Image 3</title> 
    <strThumbnail>3.jpg</strThumbnail> 
</image> 
<image id="4"> 
    <title>Image 4</title> 
    <strThumbnail>4.jpg</strThumbnail> 
</image>  
</items> 

そしてここにある:ここで

<?xml version="1.0" encoding="utf-8"?> 
    <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" 
    horizontalAlign="center" 
    verticalAlign="middle" 
    verticalGap="0" 
    width="150" 
    height="150" 
    paddingRight="5" 
    paddingLeft="5" 
    paddingTop="5" 
    paddingBottom="5"> 

    <mx:Image id="img" height="100" width="100" source="{data.strThumbnail}" /> 
    <mx:Label height="20" width="75" text="{data.title}" textAlign="center" color="0x000000" fontWeight="normal" /> 
</mx:VBox> 

items.xmlにされています。ここCustomItemRendererですこのやりとりを乗り越えて、私は何をしようとしているのかをもっと多くすることができます。読んでくれてありがとう。

答えて

0

最も簡単な方法は次のとおり

<mx:Image id="img" source="{imageTileList.selectedItem.strThumbnail}" /> 

データオブジェクトがそれの外側ではないアイテムレンダラー内で使用するためのものです。 1つのデータオブジェクトは、レンダラーに渡したxmlのイメージの1つを表します。

アイテムレンダラーhereのドキュメントを必ずチェックしてください。

関連する問題