简体   繁体   English

flex4多个img加载通用功能

[英]flex4 multiple img load generic function

I am relatively new to the Flex 4 platform (only two three months under my belt). 我对Flex 4平台还比较陌生(我只待了两个三个月)。 I will cut it short and get to the point 我会简而言之

<mx:TabNavigator....
<s:NavigatorContent...
<s:BorderContainer width="522" 
          height="138" 
          id="fstCont4" 
          backgroundAlpha="0" 
          dropShadowVisible="true" 
          x="568.25" y="177.1">
    <s:layout>
     <s:HorizontalLayout gap="0" verticalAlign="middle"/>
    </s:layout>
    <s:Label text="Lahore PIE" 
       rotation="-90"  
       fontWeight="normal" 
       fontFamily="Arial" 
       fontSize="18" 
       verticalAlign="middle" 
       textAlign="center" 
       fontStyle="normal"/>
    <mx:Image id="lhrPIE" 
        width="506" 
        height="138"/>
    <s:Button height="25" width="25" rotation="90" click="lhrPIE_Refresh_clickHandler(event)"/>
   </s:BorderContainer>

</s:NavigatorContent>
</mx:TabNavigator>

I have a contentCreationComplete event on NavigatorContent... and once that is fired i load some img's into the mx Image component. 我在NavigatorContent ...上有一个contentCreationComplete事件,一旦触发,我便将一些img加载到mx Image组件中。 I have many of these BorderContainer inside the NavigatorContent container and hence a lot of images are loaded in ContentCreation function. 我在NavigatorContent容器中有很多BorderContainer,因此在ContentCreation函数中加载了很多图像。

I have also added a button component to the BorderContainer component so that the users can manually reload a specific img from the many BorderContainer + img combos. 我还向BorderContainer组件添加了一个按钮组件,以便用户可以从许多BorderContainer + img组合中手动重新加载特定的img。 The click event as mentioned just loads the img into the img block. 提到的click事件只是将img加载到img块中。 Problem is i donot want to write event handlers for all the buttons. 问题是我不想为所有按钮编写事件处理程序。

how can i make a generic function.. 我该如何做一个泛型函数。

i have a feeling that it would be something like 我有种感觉

protected function imgRefresh_clickHandler(event:MouseEvent):void { this.lhrPIE.load("...."); 受保护的函数imgRefresh_clickHandler(event:MouseEvent):void {th​​is.lhrPIE.load(“ ....”); } }

How can i make this function generic and reference the img block of each Container generically without referencing the ID ( which are off course unique thought the app for each img block) 我如何才能使该函数通用并在不引用ID的情况下通用地引用每个Container的img块(对于每个img块,应用程序都认为这是唯一的)

If you plan on having a different button in each BorderContainer, and the order of the content is identical and fixed in each container (ie. Image is always the second item), then you could use the index to trigger a load on the corresponding Image: 如果您计划在每个BorderContainer中使用不同的按钮,并且内容的顺序在每个容器中相同且固定(即,Image始终是第二个项目),则可以使用索引触发对相应Image的加载:

imgRefresh_clickHandler(event:MouseEvent):void
{
    (event.target.parent.getChildAt(1) as Image).load();
}

where the 1 corresponds to the index at which the Image component is. 其中1对应于Image组件所在的索引。 This code assumes that the source property on the image has already been set. 此代码假定图像上的source属性已经设置。

Well done it in this way.. .hope is helps someone ... 用这种方法做得好..希望可以帮助某人...

        private var imgPattren:RegExp = /......$/;
        private var imgLoc:Array = new Array("img1.png","img2.png");



       protected function imgRefresh_clickHandler(event:MouseEvent):void
        {
                             switch(String(imgPattren.exec(String(event.currentTarget))))
                            {
                            case 'isbTW1':
                                event.currentTarget.load(imgLoc[0]);
                                break;
                            case 'isbPIE':
                                event.currentTarget.load(imgLoc[0]);
                                break;
        }
        }

How ever i still face an isssue. 我怎么仍然会遇到一个问题。 when my image fails to load i get an "image missing icon". 当我的图像无法加载时,我得到一个“图像丢失图标”。 and my Click hit area is reduced to that little icon instead of the original image. 我的点击命中区域缩小为那个小图标,而不是原始图像。 i may add the click handler to the Bordercontainer and use the method suggested by @merv 我可以将点击处理程序添加到Bordercontainer并使用@merv建议的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM