flex4多img加载通用函数

发布于 2024-10-13 12:08:50 字数 1423 浏览 10 评论 0原文

我对 Flex 4 平台还比较陌生(我只使用了两三个月)。我将简短地介绍一下,

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

我在 NavigatorContent 上有一个 contentCreationComplete 事件...一旦触发,我就会将一些 img 加载到 mx Image 组件中。我在 NavigatorContent 容器内有许多这样的 BorderContainer,因此在 ContentCreation 函数中加载了很多图像。

我还在 BorderContainer 组件中添加了一个按钮组件,以便用户可以从许多 BorderContainer + img 组合中手动重新加载特定的 img。前面提到的点击事件只是将 img 加载到 img 块中。问题是我不想为所有按钮编写事件处理程序。

我怎样才能制作一个通用函数..

我有一种感觉,它会像

受保护的函数 imgRefresh_clickHandler(event:MouseEvent):void { this.lhrPIE.load("...."); 我怎样

才能使这个函数通用并一般引用每个容器的img块而不引用ID(这当然是每个img块的应用程序所独有的)

I am relatively new to the Flex 4 platform (only two three months under my belt). 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. I have many of these BorderContainer inside the NavigatorContent container and hence a lot of images are loaded in ContentCreation function.

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. The click event as mentioned just loads the img into the img block. 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("....");
}

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薆情海 2024-10-20 12:08:50

如果您计划在每个 BorderContainer 中使用不同的按钮,并且每个容器中内容的顺序相同且固定(即图像始终是第二项),那么您可以使用索引来触发相应图像上的加载:

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

其中 1 对应于图像组件所在的索引。此代码假定图像上的 source 属性已设置。

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:

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. This code assumes that the source property on the image has already been set.

童话 2024-10-20 12:08:50

以这种方式做得很好......希望可以帮助某人......

        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;
        }
        }

但是我仍然面临问题。当我的图像无法加载时,我收到“图像丢失图标”。我的点击区域缩小为那个小图标而不是原始图像。我可以将点击处理程序添加到 Bordercontainer 并使用 @merv 建议的方法

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文