Solved

Refresh a view every load

Posted on 2008-10-30
3
1,368 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:jdunneuk
  • 2
3 Comments
 
LVL 19

Assisted Solution

by:Gary Benade
Gary Benade earned 150 total points
ID: 22883987
That component is dispatching events when things change, you should be able to listen for the urlchanged event in your container and respond to that


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

// add to your view creationComplete event
surl.addEventListener( "linkURLChanged", doUpdate);
0
 
LVL 3

Accepted Solution

by:
jdunneuk earned 0 total points
ID: 22886192
I figured it out, watching the url was not enough i put the URL in an array collection and it worked as I watched everything from there
0
 
LVL 19

Expert Comment

by:Gary Benade
ID: 22889066
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
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question