Actionscript 3 如何在AS3中从字符串数组设置图像源?
我只需要知道如何在Actionscript 3 如何在AS3中从字符串数组设置图像源?,actionscript-3,actionscript,Actionscript 3,Actionscript,我只需要知道如何在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
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>
假设您的图像位于资产中/
尝试以下操作:
newImage.source = "asset/" + arrayEntry;
将for循环中的代码修改为:
newImage.source = "asset\\" + myArray[i];
当使用包含路径的字符串时,你最好使用\\
符号。是的,我知道是这样的,但我记不起语法,也不知道在谷歌中键入什么。谢谢@GabeDougherty如果您发现此答案解决了您的问题,请单击复选框将其标记为正确。如果答案对您有帮助,您应该接受。