flex4多img加载通用函数
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您计划在每个 BorderContainer 中使用不同的按钮,并且每个容器中内容的顺序相同且固定(即图像始终是第二项),那么您可以使用索引来触发相应图像上的加载:
其中 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:
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.以这种方式做得很好......希望可以帮助某人......
但是我仍然面临问题。当我的图像无法加载时,我收到“图像丢失图标”。我的点击区域缩小为那个小图标而不是原始图像。我可以将点击处理程序添加到 Bordercontainer 并使用 @merv 建议的方法
Well done it in this way.. .hope is helps someone ...
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