[英]flex4 multiple img load generic function
我對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。 提到的click事件只是將img加載到img塊中。 問題是我不想為所有按鈕編寫事件處理程序。
我該如何做一個泛型函數。
我有種感覺
受保護的函數imgRefresh_clickHandler(event:MouseEvent):void {this.lhrPIE.load(“ ....”); }
我如何才能使該函數通用並在不引用ID的情況下通用地引用每個Container的img塊(對於每個img塊,應用程序都認為這是唯一的)
如果您計划在每個BorderContainer中使用不同的按鈕,並且內容的順序在每個容器中相同且固定(即,Image始終是第二個項目),則可以使用索引觸發對相應Image的加載:
imgRefresh_clickHandler(event:MouseEvent):void
{
(event.target.parent.getChildAt(1) as Image).load();
}
其中1對應於Image組件所在的索引。 此代碼假定圖像上的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並使用@merv建議的方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.