2012-09-27 31 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時,最好使用\\標誌。

相關問題