Image flex4多重img加载通用功能
我对Flex 4平台还比较陌生(我只工作了两到三个月)。我会简明扼要,直截了当Image flex4多重img加载通用功能,image,actionscript-3,apache-flex,flex4,Image,Actionscript 3,Apache Flex,Flex4,我对Flex 4平台还比较陌生(我只工作了两到三个月)。我会简明扼要,直截了当 <mx:TabNavigator.... <s:NavigatorContent... <s:BorderContainer width="522" height="138" id="fstCont4" backgroundAlpha="0" dropShadowVisible="true"
<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>
如果您计划在每个BorderContainer中使用不同的按钮,并且每个容器中的内容顺序相同且固定(即图像始终是第二项),则可以使用索引触发相应图像的加载:
imgRefresh_clickHandler(event:MouseEvent):void
{
(event.target.parent.getChildAt(1) as Image).load();
}
其中,1对应于图像分量所在的索引。此代码假定图像上的source
属性已经设置。通过这种方式做得很好。希望是帮助某人
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中,并使用@mervHmm建议的方法,这很好。我对这次事件一无所知。当前目标。。。然而,这是我用另一种方式重新实现的正确方法。我删除了按钮,并在img本身上添加了一个Click事件句柄。这样,我将映像重新加载到event.currentTarget.load。。。我还通过使用正则表达式匹配来检查event.Current目标,为所有对象创建了一个通用函数。我添加了一个Switch语句,检测到img块的id并加载了相应的图像