我只需要知道如何在它上面的数组的newImage.source = "asset/%myArray%";
行设置其源代码。我确信有一个简单的解决方案。我只是不确定如何在Google上提出这个问题......
<?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>
答案 0 :(得分:1)
假设您的图片位于asset/
,请尝试:
newImage.source = "asset/" + arrayEntry;
答案 1 :(得分:1)
将for循环中的代码修改为:
newImage.source = "asset\\" + myArray[i];
使用包含路径的Strings
时,最好使用\\
符号。