That still doesn't look quite right to me. I might not be reading the
snippets you posted correctly. But let's say you have a main.mxml:
---- main.mxml ----
<s:Application>
<s:TabNavigator id="tn" change="tabNavChangeHandler()/>
<ImageView id="imageView" />
<OptionsView id="optionsView" />
</s:TabNavigator>
</s:Application>
---- main.mxml ----
The tabNavChangeHandler should have code that looks like:
if (tn.selectedIndex == 1)
optionsView.addEventListener("roofColorChanged", ...);
In OptionsView, there should be code that looks like:
---- OptionsView.mxml -----
<s:Panel>
<s:Form>
<s:FormItem label="Colors:" height="200">
<mx:ColorPicker id="roofColorPKR" width="200" height="50"
change="roofColorPKR_changeHandler(event)" />
</s:FormItem>
</s:Form>
</s:Panel>
And there should be a script block in OptionsPanel.mxml that looks like:
<fx:Script>
private function roofColorPKR_changeHandler(e:Event):void
{
dispatchEvent(new Event("roofColorChanged"));
}
</fx:Script>
What you don't want to see is optionsView.roofOptions.addEventListener in
the main.mxml. The children should send a semantic event off the
containing component. You shouldn't have to access the children of the
optionsView to add a listener.
HTH,
-Alex
On 8/28/16, 6:25 PM, "CodeGirl" <[email protected]> wrote:
>I finally found an answer. Now I wonder if this was what you were saying
>all
>along and I was too focused on adding the event listener rather than
>thinking of scope. The down side is that I ended up adding four listeners
>to add one that I needed. So here is how I did it.
>
>in the tab or NavigatorContent, I added a click event and then in the
>click
>event, I fired a Metadata Event.
>Then in the parent, I created the Metadata event from the definition of
>the
>Child Panel. When that was fired, then I added the color change event
>which
>worked.
>
>Child code
>
> <fx:Metadata>
> [Event(name="roofOptionsClicked", type="flash.events.Event")]
> </fx:Metadata>
>
> protected function
> roofNavigator_clickHandler(event:MouseEvent):void
> {
> var eventObject:Event = new
> Event("roofOptionsClicked");
> dispatchEvent(eventObject);
> }
>
> <s:NavigatorContent label="Roof" id="roofNavigator"
>click="roofNavigator_clickHandler(event)">
> <options:RoofOptions id="roofOptions" width="100%"
> height="100%"
> roofcolors="{colors}"
> />
> </s:NavigatorContent>
>
>
>
>Parent Code
>
> <options:OptionsView id="optionsView"
> width="25%" height="100%"
> colors="{colors}"
> pitchs="{pitchs}"
>
> roofOptionsClicked="optionsView_roofOptionsClickedHandler(event)"
> />
>
> protected function
>optionsView_roofOptionsClickedHandler(event:Event):void
> {
>
> optionsView.roofOptions.addEventListener(ChangeRoofColor.CHANGED,
>roofOptions_roofColorChangedHandler);
> }
>
> protected function
>roofOptions_roofColorChangedHandler(event:ChangeRoofColor):void
> {
>
>
>
>
>--
>View this message in context:
>http://apache-flex-users.2333346.n4.nabble.com/EventListener-null-referenc
>e-error-tp13436p13462.html
>Sent from the Apache Flex Users mailing list archive at Nabble.com.