Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

Accessing Parent Proerty From Child Component in Flex

Hi,

I am trying to have the component, whose code I pasted below, access a property called xQuery from its direct parent a module called survey.

Inside survey xQuery is a variable that is public and XMLList.

Any help with this undefined property error would be greatly appreciated.
<?xml version="1.0" encoding="utf-8"?>


	<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"  width="580" height="202" layout="absolute" title="Question Section and Number" color="#FFFFFF" themeColor="#008C69" creationPolicy="auto" creationComplete="radioInit()"> 
		
<mx:Script>

 
<![CDATA[

import mx.core.Application;

[Bindable]
public var neededData:String;

public function radioInit():void
{
neededData = parentDocument.xQuery.question;
}

]]>

</mx:Script>


		<mx:Text x="10" y="15"  fontSize="14" id="queryText" width="477" height="61" color="#3D3D3D"  text="{neededData}"/>
		<mx:RadioButton x="10" y="77" label="Answer" id="queryAnswer" fontSize="14" color="#3D3D3D"/>
		<mx:HRule x="10" y="67" width="540" height="2"/>
		<mx:Button x="247" y="119" label="Next" color="#3D3D3D" themeColor="#008C69" id="querySubmit"/>
	</mx:Panel>

Open in new window

0
jsuissa
Asked:
jsuissa
  • 5
  • 5
1 Solution
 
moagriusCommented:
just this line:

neededData = parentDocument.xQuery.question;

should be just parent.xQuery.question;

*but* you might need to cast "parent" to whatever it's class name is - so if the class with the public variable xQuery is called "MyClass" you'd do it like this:

MyClass(parent).xQuery.question;
0
 
jsuissaAuthor Commented:
Hi,

I tried that, but I think it believes the Canvas in the module is its parent and not the module itself, which class is named survey.

I included the module below because I'm sure that will help with this.

Thanks so much.
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:components="components.*" width="800" height="400" creationPolicy="auto" creationComplete="queryInit()">
		
<mx:Script>
	<![CDATA[
			import mx.rpc.events.ResultEvent;
		    import mx.rpc.events.ResultEvent;
			import mx.rpc.events.FaultEvent;
			
		    [Bindable]
            public var xQuery:XMLList;
            
            
            public function queryInit():void
            {
            	xmlQuestions.send();
                
            }               
            
            // Result handler - gets called after RSS is loaded.
            public function queryHandler(event:ResultEvent):void
            {
                xQuery = event.result.question;
                
            }
	]]>
</mx:Script>
		
		<mx:Canvas x="0" y="0" width="800" height="400" color="#3D3D3D" themeColor="#008C69" backgroundColor="#FFFFFF" backgroundAlpha="0.1" borderColor="#FFFFFF" alpha="1.0" creationPolicy="auto">
	<mx:ApplicationControlBar y="358" width="770" fillAlphas="[0.9, 0.9]" x="10" height="32">
		<mx:Label text="Survey Label" id="barLabel" width="407"/>
		<mx:VRule width="1" height="20"/>
		<components:progress width="318" labelPlacement="center" fontWeight="normal">
			
		</components:progress>
	</mx:ApplicationControlBar>

<components:radioQuery x="200" y="47" creationPolicy="auto" id="queryPanel">
	
</components:radioQuery>

	</mx:Canvas>
	
		<mx:HTTPService id="xmlQuestions"
		url="http://www.visualdemocracy.com/questions.xml"
		result="queryHandler(event)"
		resultFormat="e4x"/>
		
				
</mx:Module>

Open in new window

0
 
moagriusCommented:
is the first component you posted "progress"?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jsuissaAuthor Commented:
Nope, its the survey question itself in the module named "survey" and its named "queryPanel"
0
 
moagriusCommented:
oh yeah :/

wierd...  both should work - and my Flex is uninstalled, so i can't test anything at the moment...

i'd try various combination of parentDocument, outerDocument and parent.parentDocument...

also might be possible to bind directly to xQuery since it's not available immediate:

text="{parentDocument.xQuery.question}"

if that fails, hopefully somebody else can jump in that actually has flex installed :/
0
 
jsuissaAuthor Commented:
Thanks so much! Direct binding to {parentDocument.xQuery.query} worked. The only thing I'm curious about now is that instead of showing the text inside the first instance of the XML element <query>Text<query>, it shows the XML tags and the content for every element name query in the entire tree?
0
 
moagriusCommented:
try {parentDocument.xQuery.query.text()}
0
 
jsuissaAuthor Commented:
The advice provided was comprehensive and offered a number of different solutions to the issue I was having.
0
 
jsuissaAuthor Commented:
The solutions you provided were great I'm just still have an issue now were the tags are now gone, but it still is displaying every instance instead of one at a time.
0
 
moagriusCommented:
do you just want the first one?

try {parentDocument.xQuery[0].query.text()}

or maybe

{parentDocument.xQuery.query[0].text()}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now