?
Solved

Accessing Parent Proerty From Child Component in Flex

Posted on 2010-01-12
10
Medium Priority
?
695 Views
Last Modified: 2013-11-11
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
Comment
Question by:jsuissa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 19

Expert Comment

by:moagrius
ID: 26298173
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
 

Author Comment

by:jsuissa
ID: 26299157
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
 
LVL 19

Expert Comment

by:moagrius
ID: 26299175
is the first component you posted "progress"?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jsuissa
ID: 26299205
Nope, its the survey question itself in the module named "survey" and its named "queryPanel"
0
 
LVL 19

Expert Comment

by:moagrius
ID: 26299255
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
 

Author Comment

by:jsuissa
ID: 26299279
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
 
LVL 19

Accepted Solution

by:
moagrius earned 2000 total points
ID: 26299291
try {parentDocument.xQuery.query.text()}
0
 

Author Closing Comment

by:jsuissa
ID: 31676194
The advice provided was comprehensive and offered a number of different solutions to the issue I was having.
0
 

Author Comment

by:jsuissa
ID: 26299443
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
 
LVL 19

Expert Comment

by:moagrius
ID: 26299460
do you just want the first one?

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

or maybe

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

741 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