Link to home
Start Free TrialLog in
Avatar of jdunneuk
jdunneuk

asked on

Refresh a view every load

Hi Guys

 I have a custom component an extended label and need a way of refreshing the view it is contained in everytime it is called.

The problem is only the URL will change which is done from within the component so I have no way to know when to invalidate the prop.

I have included the call and two files,

<common:customLabel screenID="overviewLinks" identify="accountType_title" linkName="Account Type" styleName="txtLabel" width="100" height="20" />


thanks,

John





<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off" activate="invalidateProperties()">
	<mx:Script>
	 <![CDATA[
	 	import mx.collections.ArrayCollection;
		import mx.controls.Image;			
		import mx.managers.CursorManager;
		import flash.events.*;
		import com.sunlife.us.workbench.util.common.linkUrlFunction;
		
 
		[Bindable]	
			public var returnedArray : ArrayCollection = new ArrayCollection();
		[Bindable]	
			public var _linkURL:String = new String();
		[Bindable]	
			public var linkImage:String = new String();
		[Bindable]	
			public var	visibleImage:Boolean = false;
		[Bindable]	
			public var	screenID : String  = new String();
		[Bindable]
			public var identify : String  = new String();
		[Bindable]
			public var _linkName : String = new String();
	
			
		override protected function commitProperties():void
		
			{
				identify = this.identify;
				screenID = this.screenID;				
				returnedArray = linkUrlFunction.returnLink(identify,screenID);
				linkURL = String(returnedArray.getItemAt(0));
				linkImage = String(returnedArray.getItemAt(1));
				visibleImage = returnedArray.getItemAt(2);
 
				if(visibleImage){
					this.visibleImage = true;
				}
			}
			
 
			[Bindable(event="linkNameChanged")]
			public function get linkName():String {
			  return _linkName;
			}
			
			public function set linkName(value:String):void {
			  _linkName = value;
			
			  // calling this method will cause commitProperties() to be called in the next update
			  invalidateProperties();
			
			  // note that the event you dispatch has the same name as the one given in the Bindable metatag
			  dispatchEvent(new Event("linkNameChanged"));
 
			}
			
			
			
			// check the url also as the url may only change on some products
		
			[Bindable(event="linkURLChanged")]
			public function get linkURL():String {
			  return _linkURL;
			}
			
			public function set linkURL(value:String):void {
			  _linkURL = value;
			
			  // calling this method will cause commitProperties() to be called in the next update
			  invalidateProperties();
			
			  // note that the event you dispatch has the same name as the one given in the Bindable metatag
			  dispatchEvent(new Event("linkURLChanged"));
 
			}
 
 
 
	         public function linkHandler():void 
	         {
	         	identify = this.identify;
				screenID = this.screenID;				
				returnedArray = linkUrlFunction.returnLink(identify,screenID);
				
				var link2Use :String = new String();
				link2Use = String(returnedArray.getItemAt(0));
	         	
		        // Open the link in a new window, 
		        navigateToURL(new URLRequest(link2Use), '_link')
		     }
	       ]]>
	</mx:Script>
		
	<mx:HBox horizontalGap="-2" horizontalScrollPolicy="off" width="100%">
		<mx:Text text="{_linkName}" paddingRight="0" paddingLeft="0" id="textDisplay"/>
		<mx:Image enabled="{this.visibleImage}" visible="{this.visibleImage}" horizontalAlign="center" verticalAlign="middle"  source="{this.linkImage}" click="linkHandler()" buttonMode="true" scaleContent="true" width="17" height="17"/>
		
	</mx:HBox>
 
</mx:Canvas>
 
 
 
 
 
 
 
 
 
 
 
 
 
package custom
{
	import mx.collections.ArrayCollection;
	import com.sunlife.us.workbench.model.annuity.ModelLocatorAnnuity;
	import mx.utils.StringUtil;
	
	
	
	public class linkUrlFunction
	{
		
		public static function returnLink(linkID : String, screenID : String):ArrayCollection
		{
			screenID= StringUtil.trim(screenID);
			var modelAnnuity : ModelLocatorAnnuity = ModelLocatorAnnuity.getInstance();
			
			 var returnArray : ArrayCollection = new ArrayCollection();
			 var returnUrl : String = new String;
			 var returnImage : String = new String;;
			 var imagePath :String = "assets/images/";
			 var linkImage:String = new String;;
			 var identifyierArray : Object = new Object;
			 var visible : Boolean = new Boolean;
			 
			identifyierArray = new ArrayCollection;
			visible = false;
		
		
 		if( modelAnnuity.annuityOverviewVO.annuityWB2Links != null){
			switch(screenID)
			{
			case "bonusValuesLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.bonusValuesLinks;		
				break;
			
			case "claimsLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.claimsLinks;
				break;
				
			case "deathBenefitsLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.deathBenefitsLinks;
				break;
		
			case "investmentsLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.investmentsLinks;
				break;
		
			case "livingBenefitsLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.livingBenefitsLinks;
				break;
			
			case "overviewLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.overviewLinks;
				break;
			
			case "rmdLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.rmdLinks;
				break;
			
			case "specialFeaturesLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.specialFeaturesLinks;
				break;
			
			case "taxLinks":
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.taxLinks;
				break;
			
			case "transactionsLinks": 
				identifyierArray = modelAnnuity.annuityOverviewVO.annuityWB2Links.transactionsLinks;
				break;
				
			default:
				
				returnArray.addItemAt("" , 0);
				returnArray.addItemAt("" , 1);
				returnArray.addItemAt("",2);
			}
		}
			else{
				
			returnArray.addItemAt("" , 0);
			returnArray.addItemAt("" , 1);
			returnArray.addItemAt("",2);
			trace("******************************************** ");
		
		}
		if (identifyierArray == null){
			
			returnArray.addItemAt("" , 0);
			returnArray.addItemAt("" , 1);
			returnArray.addItemAt("",2);
			trace("null object encountered ie. no array returned for current set for " + screenID);
		}
		
		else {
			
			if( identifyierArray.length > 0)
			{
				
				 for(var h : Number = 0; h < identifyierArray.length; h++)
				 {
					 if(StringUtil.trim(identifyierArray[h].flexId) == StringUtil.trim(linkID))
					 {
					 	returnUrl = String(identifyierArray[h].url)	
					 	linkImage = String(identifyierArray[h].iconType);
					 	h = identifyierArray.length; 		 	
					 }
				 }
				 
				 if((linkImage == null) || (linkImage.length < 1) || (returnUrl == "") ){			 	
					 visible = false;
					}
				else{
					
					returnImage = String(imagePath + StringUtil.trim(linkImage) +".gif")
					trace(returnImage);
					visible = true;	
					}
					
				returnArray.addItemAt(returnUrl , 0);
				returnArray.addItemAt(returnImage , 1);
				returnArray.addItemAt(visible,2);
		
			}
			
		}
	
		return(returnArray);
		}
	}
 
}

Open in new window

SOLUTION
Avatar of Gary Benade
Gary Benade
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Congrats, very glad to hear you found a solution, good job!. Out of professional interest I'd like to see what it was if you don't mind, never too old to learn, thanks