2012-09-27 30 views
-1

我只需要知道如何在上面的数组的newImage.source = "asset/%myArray%";行上设置它的源代码。我确定有一个简单的解决方案。我只是不知道你的形象如何字在谷歌的问题...如何在AS3中设置字符串数组的图像源?

<?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

如果他们帮助你,你应该接受答案。 – Gio

回答

1

假设住在asset/试试这个:在你的for循环这个

newImage.source = "asset/" + arrayEntry; 
+0

是的工作,我知道这是类似的东西,但我只是不记得语法,并不能想到要输入到谷歌。谢谢! –

+0

@GabeDougherty如果你发现这个答案解决了你的问题,请点击复选框将其标记为正确。 – francis

1

修改代码:

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

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

相关问题