Flex Mobile Project,在数组中插入多个Image对象

时间:2012-08-01 11:35:29

标签: arrays image flex flex-mobile

我已将索引编入索引,如下所示:

<s:Image id="imgListaTaskAnalysis0" left="20" top="110" width="200" height="200"/>
<s:Image id="imgListaTaskAnalysis1" left="20" top="360" width="200" height="200"/>
<s:Image id="imgListaTaskAnalysis2" left="20" top="360" width="200" height="200"/> 

等等..

我想把它们放在一个数组中,所以:

public var arrayImg:Array = new Array(imgListaTaskAnalysis0,imgListaTaskAnalysis1,imgListaTaskAnalysis2);

但我不能给他们一个消息来源:

for(var i:Number=0;i<=arrayImg.length;i++)
                arrayImg[i].source = cuboImmagini.path;

这种方式不起作用,不给他们任何来源。有办法做到这一点吗?

这是我项目中感兴趣的部分:

public var arrayImg:Array = new Array(imgListaTaskAnalysis0,imgListaTaskAnalysis1);
/*          DICHIARAZIONE IMMAGINI          */
public var cuboImmagini:Object = {path:"../assets/cuboImmagini.png"};
public var exit:Object = {path:"../assets/exit.png"};
public var home:Object = {path:"../assets/home.png"};
/*          FINE DICHIARAZIONE IMMAGINI     */

/*          FUNZIONI            */

//  cambiaPagina
public function cambiaPagina(prossimaPagina:String):void
{   
currentState = prossimaPagina;
}

// chiudiApplicazione
protected function chiudiApplicazione(event:MouseEvent):void    
{
NativeApplication.nativeApplication.exit();
}
public function carica():void
        {
            arrayImg[0].source = cuboImmagini.path;
            arrayImg[1].source = home.path;
            cambiaPagina("HomePage");
        }
        /*          FINE FUNZIONI       */
    ]]>
</fx:Script>
<s:states>
    <s:State name="PaginaPresentazione"/>
    <s:State name="HomePage"/>
    <s:State name="ListaTaskAnalysis"/>
    <s:State name="ScegliAzioneTaskAnalysis"/>
</s:states>
<fx:Declarations>
</fx:Declarations>


    <!-- =================================== MXML =================================== -->

    <!-- =================================== PaginaPresentazione =================================== -->
<s:Group id="gruppoPaginaPresentazione" includeIn="PaginaPresentazione" left="0" right="0" top="0" bottom="0"
         horizontalCenter="0" verticalCenter="0">
    <s:Button id="btnPresentazione" right="10" bottom="10" label="INIZIA"
              click="carica()"/>
</s:Group>
    <!-- =================================== HomePage =================================== -->
<s:Group id="gruppoHomePage" includeIn="HomePage,PaginaPresentazione" left="0" right="0" top="0"
         bottom="0" horizontalCenter="0" verticalCenter="0">

    <s:Button id="btnVaiTaskAnalysis" includeIn="HomePage" width="600" height="90"
              label="TASK ANALYSIS" click="cambiaPagina('ListaTaskAnalysis')" fontSize="50"
              horizontalCenter="0" verticalCenter="80"/>
    <s:Button id="btnVaiStorieSociali" includeIn="HomePage" width="600" height="90"
              label="STORIE SOCIALI" fontSize="50" horizontalCenter="0" verticalCenter="-80"/>

</s:Group>
    <!-- =================================== /HomePage =================================== -->

<s:Group id="gruppoListaTaskAnalysis" includeIn="ListaTaskAnalysis" left="0" right="0" top="0" bottom="0"
         horizontalCenter="0" verticalCenter="0">
    <s:Group id="gruppoBottoniListaTaskAnalyis" left="0" right="0" top="0" height="90"
             horizontalCenter="0">
        <s:Button id="btnExitListaTaskAnalysis" right="10" top="5" width="80" height="80"
                  icon="assets/exit.png"  click="chiudiApplicazione(event)"/>
        <s:Button id="btnHomeListaTaskAnalysis" right="100" top="5" width="80" height="80"
                  icon="assets/home.png" click = "cambiaPagina('HomePage')"/>
    </s:Group>
    <s:Image id="imgListaTaskAnalysis0" left="20" top="110" width="200" height="200"
             source="assets/cuboImmagini.png"/>
    <s:Image id="imgListaTaskAnalysis1" left="20" top="360" width="200" height="200"/>
    <s:Button id="btnSegreto1" left="10" bottom="10" width="90" height="90" alpha="0.1" click="combinazioneSegreta(1)"/>
    <s:Button id="btnSegreto2" right="10" bottom="10" width="90" height="90" alpha="0.1" click="combinazioneSegreta(2)"/>

</s:Group>
<s:Group id="gruppoListaTaskAnalysis0" includeIn="ScegliAzioneTaskAnalysis" left="0" right="0"
         top="0" bottom="0" horizontalCenter="0" verticalCenter="0">
    <s:Group id="gruppoBottoniListaTaskAnalyis0" left="0" right="0" top="0" height="90"
             horizontalCenter="0">
        <s:Button id="btnExitScegliAzioneTaskAnalysis0" right="10" top="5" width="80" height="80"
                  icon="assets/exit.png"  click="chiudiApplicazione(event)"/>
        <s:Button id="btnHomeScegliAzioneTaskAnalisys" right="100" top="5" width="80" height="80"
                  icon="assets/home.png" click = "cambiaPagina('HomePage')"/>
    </s:Group>

</s:Group>
    <!-- =================================== /HomePage =================================== -->

提前致谢..

1 个答案:

答案 0 :(得分:0)

我解决了问题。我在创建数据时将数据放入数组中:

<s:Image id="img" creationComplete = "loadImage(event,this.img,0) />
---------------------------------------------------------------------
public function loadImage(e:FlexEvent,img:Image,num:Number):void
{
  array[num] = img;
}

非常感谢..