简体   繁体   English

如何在Flex中显示数组中的图像?

[英]How to display images from an array in Flex?

I'm making a Matching Game in Flex. 我正在用Flex做一个配对游戏。 I want to have images from one array on my left and images from the second array on my right, so that user can drag&drop images from the left onto matching images on the right. 我希望左侧有一个阵列的图像,右侧有第二个阵列的图像,以便用户可以将左侧的图像拖放到右侧的匹配图像上。

I have mx:HBox and two mx:VBox inside. 我里面有mx:HBox和两个mx:VBox。 Now, how can I display images in VBox that I have in my gameArray, if the length of my array (amount of images) may differ? 现在,如果阵列的长度(图像数量)可能不同,如何在我的gameArray中的VBox中显示图像? I would have to create as many mx:Image as the length of my gameArray, but how do I do it in MXML? 我必须创建与gameArray长度一样多的mx:Image,但是如何在MXML中实现呢?

为什么不将ListitemRenderer一起使用以显示图像?

I have all my data in an array and prefer to keep it like this. 我将所有数据都放在一个数组中,并且喜欢这样保存。 I just dont understand why my code doesn't work... 我只是不明白为什么我的代码不起作用...

<mx:ArrayCollection id="myAC" source="{gameArray}"/>
<mx:VBox width="50%" height="100%">
<mx:Repeater id="rp" dataProvider="{myAC}">
<mx:Image source="{rp.currentItem}"/>
</mx:Repeater>
</mx:VBox>

The code is taken straight from http://livedocs.adobe.com/flex/3/html/help.html?content=repeater_3.html 该代码直接从http://livedocs.adobe.com/flex/3/html/help.html?content=repeater_3.html获取

Why doesn't it display the images? 为什么不显示图像? I debugged my code to make sure that the array has correct data. 我调试了代码,以确保该数组具有正确的数据。 The string in, eg gameArray[1] will be "assets/image.jpg" and if I just write it as a source, it works. 例如gameArray [1]中的字符串将是“ assets / image.jpg”,如果我只是将其写为源代码,它就可以工作。 With dynamic, it does not. 使用动态,则不会。 Maybe rp.currentItem is not exactly what I should use in this case?? 也许rp.currentItem并不是我在这种情况下应该使用的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM