Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2009, 09:42 PM   PM User | #1
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,046
Thanks: 9
Thanked 81 Times in 81 Posts
jerry62704 is on a distinguished road
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
jerry62704 is offline   Reply With Quote
Old 02-27-2009, 07:54 PM   PM User | #2
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,046
Thanks: 9
Thanked 81 Times in 81 Posts
jerry62704 is on a distinguished road
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.
__________________
.
.
...and gladly would he learn and gladly teach

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

Last edited by jerry62704; 02-27-2009 at 07:56 PM..
jerry62704 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:14 AM.


Advertisement
Log in to turn off these ads.