flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From CodeGirl <MichelleNicho...@yahoo.com>
Subject Re: EventListener null reference error
Date Sun, 28 Aug 2016 15:52:17 GMT
You just wonderfully described what I suspected was causing my problem and I
appreciate that it was designed that way.  Except when it came to my event
listener.  I need to know in a grand parent when an option is changed at the
grand child level.  Sure the event wont be triggered until I am in the great
grandchild.  And thats fine.  But the problem is creating the eventlistener
at the great grandparents level when the great grandchild has not yet been
instantiated.  I am not trying to pass data down.  Though I am doing that
and thanks to your description, I may need to rethink that.  But my problem
is not about passing data down but rather setting up an eventlistener up. 
Which yes, it will pass data up too.  I am using an event class to do this. 
In this case, the selected url to the texture I need to use as a skin to my
3D image.  But since my first attempt to describe what is giving me an
error, I will attempt some code.

I have the main app which displays a tab Navigator for the actual app, the
settings, and company.  Here, I am loading all the lookup tables which I do
push down to the children because I have struggled with data not displaying
properly because data has not yet loaded.  Getting the lookup data here has
solved this problem.
The first tab is a Group which is the main app.  Inside this MXML file are
two MXML components which are panels.  Also, this is where I have my event
listeners
One panel is the imagePanel which displays the 3D image with the options
selected in the Options Panel
The second panel is the Options Panel.  In that panel, I have the Navigator
Tabs which associated in each tab is the Barn Options which are the length
width, height, the pitch and barn texture.  
In the Roof Options tab, it lists the roof color, the over hang, and if you
want a facad for the over hang.
The third tab is the Misc Options such as do you want a porch or do you want
vents in the roof and such.

So the grand parent is the where I listen for changes in options and then
passes those changes to the image panel.  So, here is some of my code.  The
first is from the Grand Parent creation complete function.
Notice I have the roof color event listener commented out so my app runs
without error.  Notice that the barn event listeners are fine since that tab
is instantiated automatically.  But I need the roof color changed event
listener.  Well and I will need event listeners for all the other options in
all the options tabs.

			protected function group1_creationCompleteHandler(event:FlexEvent):void
			{
				defaultColorURL = colors.lookupColorByID(defaultcolorID).url;
				defaultRoofColorURL = colors.lookupColorByID(defaultroofcolorID).url;
				imagePanel.barn = new Barn(defaultWidth, defaultLength, defaultHeight,
defaultPitch);
				imagePanel.barn.barnAngle = imagePanel.sidesDDL.selectedItem.angle;
				loaders = new Dictionary();
				images = new Dictionary();
				var urlLoader:URLLoader = new URLLoader();
				urlLoader.addEventListener(Event.COMPLETE,
group1_urlLoaderCompleteHandler);
				urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
				urlLoader.load(new URLRequest(defaultRoofColorURL));
				loaders[urlLoader] = "Roof";
				urlLoader = new URLLoader();
				urlLoader.addEventListener(Event.COMPLETE,
group1_urlLoaderCompleteHandler);
				urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
				urlLoader.load(new URLRequest(defaultColorURL));
				loaders[urlLoader] = "Sides";

				barnSide = defaultsideID;
//				optionsView.roofOptions.addEventListener(ChangeRoofColor.CHANGED,
roofOptions_roofColorChangedHandler);

			
optionsView.barnOptions.barnDimensionsFRM.addEventListener(ChangeWidth.CHANGED,
barnDimensionsFRM_widthSPRChangeHandler);
			
optionsView.barnOptions.barnDimensionsFRM.addEventListener(ChangeLength.CHANGED,
barnDimensionsFRM_lengthSPRChangeHandler);
			
optionsView.barnOptions.barnDimensionsFRM.addEventListener(ChangeHeight.CHANGED,
barnDimensionsFRM_heightSPRChangeHandler);
			
optionsView.barnOptions.barnDimensionsFRM.addEventListener(ChangePitch.CHANGED,
barnDimensionsFRM_pitchGroupChangeHandler);
				optionsView.barnOptions.addEventListener(ChangeColor.CHANGED,
barnOptions_colorChangedHandler);
			}
			
Just in case there might be some reason why you may need to know how I am
firing my events, here is some of the code of one of my grandchildren.


<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
		 xmlns:s="library://ns.adobe.com/flex/spark" 
		 xmlns:mx="library://ns.adobe.com/flex/mx" 
		 xmlns:options="views.options.*"
		 width="400" height="300"
		 >
	
	<fx:Metadata>
		[Event(name="roofColorChanged", type="events.ChangeRoofColor")]
	</fx:Metadata>
	
	<fx:Script>
		
	</fx:Script>
	<s:Form>
		
		<s:FormItem label="Colors:" height="200">
			<mx:ColorPicker id="roofColorPKR" width="200" height="50"
							swatchPanelStyleName="rcpStyle"
							editable="false"
							dataProvider="{roofcolors.dataList}"
							labelField="name"
							colorField="color"
							selectedIndex="{lookupRoofColorsNdx()}"
							change="roofColorPKR_changeHandler(event)" 
							/>
		</s:FormItem>

And here is the event class

package events
{
	import flash.events.Event;
	
	public class ChangeRoofColor extends Event
	{
		public static const CHANGED:String = "roofColorChanged";
		public var url:String;
		
		public function ChangeRoofColor(type:String, url:String)
		{
			super(type);
			this.url = url;
		}
	}
}



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/EventListener-null-reference-error-tp13436p13450.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Mime
View raw message