【问题标题】:Flex Mobile Project, insert multiple Image object in arrayFlex Mobile Project,在数组中插入多个图像对象
【发布时间】:2012-08-01 11:35:28
【问题描述】:

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

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

提前谢谢..

【问题讨论】:

  • 我的猜测是您试图在实例化组件实例之前为它们提供源。您的 for 循环在 Flex 创建生命周期的哪个阶段发生?您是否收到特定错误?
  • 我没有收到错误,只是不起作用..图像以静态方式实例化,所以在创建完成之前没有实例化吗?循环发生在创建的处理程序中完成有图像的状态..
  • 请“量化”不起作用?如果您没有收到错误消息;你期望你没有得到什么行为?是的,MXML 中的组件将在 creationComplete 执行之前创建。您的循环是否在 creationComplete 事件处理程序中运行?
  • 是的,它在 creationcomplete 处理程序中。我的图像应该得到源,但它们是不可见的,所以我认为不明白..
  • 您提供的代码中的任何内容都不会使图像不可见。也许您需要共享更多代码,包括 MXML 模板的结构。

标签: arrays image apache-flex flex-mobile


【解决方案1】:

我解决了这个问题。我在创建图像时将它们放入数组中:

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

还是谢谢..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    相关资源
    最近更新 更多