-1

我只需要知道如何在它newImage.source = "asset/%myArray%";上面的数组中设置它的源。我确信有一个简单的解决方案。我只是不确定如何在谷歌上表达这个问题......

<?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="955" minHeight="600" applicationComplete = "init()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[

        //Gabe Dougherty
        //n221
        //9-27-12

        import mx.controls.Image;

        //array of movies
        public var myArray:Array = ["batman.jpg","cabin.jpg","christmasVaction.jpg","inception,jpg"];

        //init function
        public function init():void{

            //loops 4 times
            for(var i:Number = 0; i < myArray.length; i++){

                var arrayEntry:String = myArray[i];

                //makes new image
                var newImage:Image = new Image();

                //sets the image source for each image
                newImage.source = "asset/%myArray%";

                //adds the image to the stage
                grpMovies.addElement(newImage);
            }
        }

    ]]>
</fx:Script>
<s:HGroup id="grpMovies" x="430" y="61" width="200" height="200">
</s:HGroup>
</s:Application>
4

2 回答 2

1

假设您的图像存在,请asset/尝试以下操作:

newImage.source = "asset/" + arrayEntry;
于 2012-09-27T21:57:14.260 回答
1

将 for 循环中的代码修改为:

newImage.source = "asset\\" + myArray[i];

使用Strings包含路径时,您最好使用\\标志。

于 2012-09-27T21:57:37.423 回答