Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts

    Question Reference in AS to component

    I have a mxml that I'm breaking into components where I can. I have this structure:
    Code:
    /src
      FSCalc2.mxml
      /scripts
          FSCalc.as
      /DHSComponets
          DHSNotice.mxml
    Other files are there, but these are the ones that matter. When I broke it into pieces, the AS file no longer sees the notice fields that are now in DHSNotice.mxml.

    This produces the error:
    Code:
    noticeTextTitle.htmlText = englishNoticeTextTitle;
    noticeTextTop.htmlText = englishNoticeTextTop;
    noticeTextList.htmlText = englishNoticeTextList;
    noticeTextBottom.htmlText = englishNoticeTextBottom;
    "1120: Access of undefined property noticeTextTitle." for each of the lines (and the Spanish equivalents).

    The component file has this:
    Code:
    <mx:Text id="noticeTextTitle"
    	htmlText="{englishNoticeTextTitle}"
    	text="ffff"
    	fontSize="18"
    	horizontalCenter="0"
    	top="0"/>
    Any ideas of how to reference objects in the component file from AS?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #2
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    OK, I found the solution. I'm putting it here so others can learn something that
    apparently was very, very hard.

    Refreshing the problem: I had a large mxml file I wanted to break into components per the suggestion at the Adobe tutorial. I figured the heading, a notice area and a footer would be a good first start to separate. Each has a connection to something else. The header and footer have links. The notice area has text that changes from English to Spanish if the user clicks a button in the main (application) routine.

    To fix the link in the header and footer, I had to add:
    Code:
    <mx:Script>
    	<![CDATA[
    	
    		public function linkIDHS(url:String):void
    		{
    			navigateToURL(new URLRequest(url));  <===========
    		}		
    
    	]]>
    </mx:Script>
    
    <!-- ***************************************************************** -->
    <!-- ** start of the header area ************************************* -->
    ...	<mx:LinkButton id="headerIDHSLinkText" 
    		label="Illinois Department of Human Services"
    		fontFamily="Arial"
    		fontSize="12"
    		fontWeight="bold"
    		click="linkIDHS('http://www.dhs.state.il.us')"  <========
    		left="80" top="0"/>
    Same "click" and public function on both. This seems pretty standard.

    To fix the button in the main application file, I changed the notice mxml to:
    Code:
    <mx:Script>
    	<![CDATA[
    		[Bindable] public var noticeTextTitle:String; <=====
    		[Bindable] public var noticeTextTop:String;
    		[Bindable] public var noticeTextList:String;
    		[Bindable] public var noticeTextBottom:String;
    	]]>
    </mx:Script>
    This surfaces the variables that are set below. Now the script can set them (public) from outside of here.

    Code:
    <!-- ***************************************************************** -->
    <!-- ** start of the notices area ************************************ -->
    ...
    		<mx:Text id="noticeCompTextTitle"
    	 		htmlText="{noticeTextTitle}"   <=====
    	 		text="Text Title"
    	 		fontSize="18"
    	 		horizontalCenter="0"
    	 		top="0" />
    The local public variable, noticeTextTitle, is set in the script to either the Spanish or English variable that holds the title.

    And changed the script to:
    Code:
    	import DHSComponents.*;
    
    ...
    	noticeComp.noticeTextTitle = englishNoticeTextTitle.toString();
    	noticeComp.noticeTextTop = englishNoticeTextTop.toString();
    	noticeComp.noticeTextList = englishNoticeTextList.toString();
    	noticeComp.noticeTextBottom = englishNoticeTextBottom.toString();
    The application file:
    Code:
    	xmlns:DHSComp="DHSComponents.*"
    ...
    <!-- ***************************************************************** --> 
    <!-- ** start of the notice area ************************************* --> 
    		<DHSComp:DHSNotice id="noticeComp" <====
    			noticeTextTitle="{englishNoticeTextTitle}"
    			noticeTextTop="{englishNoticeTextTop}"
    			noticeTextList="{englishNoticeTextList}"
    			noticeTextBottom="{englishNoticeTextBottom}"			
    			/>
    Now I'm going to try to explain the above. Please correct any misinformation.

    The invoking (line 74) of the component establishes an id of "noticeComp"
    that prefixes the public variables set (line 64-67). Those lines have Spanish
    equivalents lower in the script. The default, English, is set in the invocation
    of DHSNotice (line 75-78).

    I hope this will help others working with Flex.
    Last edited by jerry62704; 02-27-2009 at 07:56 PM.
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •