• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • Last Modified:

private function works only without TabNavigator?

Hello,
with PHP and MySql i output some data in a grid, everything works perfect.
These two grids are VBoxes. Now if i try to put these VBoxes in a TabNavigator i get an error. Anything does not work in my private function. Without the TabNavigator everything works.
Please can somebody help me?

Thanks

private function calcSumEK():void {
            	var amount:Number = 0;
				if(produkteGrid.dataProvider) {
					for(var i:int = 0; i<produkteGrid.dataProvider.length; i++) {
						amount += Number(produkteGrid.dataProvider.getItemAt(i).EK) * Number(produkteGrid.dataProvider.getItemAt(i).Vorrat);
					} 
					sumEK.text = roundDecimal(amount,2).toString() + " Euro";
				}
            }
            
            private function roundDecimal(num : Number, decimals : Number):Number {
				var tempNum1 : Number = Number((1 <<decimals).toString(2));
				var tempNum2 : Number = Number((1 <<decimals).toString(2));
				return Math.round(tempNum1*num)/tempNum2;
			}

<mx:HTTPService id="produkteListe" useProxy="false" url="{parentApplication.phpURL}" method="POST" result="calcSumEK()">
		<mx:request>
		  <getProdukteEditListe>true</getProdukteEditListe>
		</mx:request> 
	</mx:HTTPService>

<mx:TabNavigator width="100%" height="100%" id="nav2" selectedIndex="0">
	
	<!--   Leistungen   -->
	
		<mx:VBox label="Leistungen" height="100%" width="100%"  paddingLeft="8" paddingTop="8" paddingRight="8" paddingBottom="8" backgroundColor="#f8f8f8" borderColor="#e0e0e0" borderThickness="1" borderStyle="solid">
			<mx:Text text="Leistungen" fontWeight="bold" fontSize="14" color="#3D98FF"/>
			<mx:DataGrid variableRowHeight="true" editable="true" height="100%" itemEditEnd="updateLeistung(event)" id="leistungenGrid" wordWrap="true" dataProvider="{leistungenListe.lastResult.leistungen.leistung}" width="100%">
				<mx:columns>
					<mx:DataGridColumn dataField="ID" editable="false" width="35"  />
					<mx:DataGridColumn dataField="Name" />
			        <mx:DataGridColumn dataField="Preis" width="60" textAlign="right" labelFunction="formatPreis" />
				</mx:columns>
			</mx:DataGrid>
			<mx:HBox width="100%">
				<mx:Spacer width="100%" />
				<mx:Button label="-" click="loescheLeistung.send()" />
			</mx:HBox>
			<mx:VBox width="100%" paddingTop="10" height="130" horizontalAlign="left" verticalAlign="bottom">
				<mx:Text text="Neue Leistung" fontWeight="bold" width="100%"/>
				<mx:HBox width="100%">
					<mx:Label text="Bezeichnung:" width="100" />
					<mx:Spacer width="20" />
					<mx:TextInput id="neueLeistungName" width="100%" />
				</mx:HBox>
				<mx:HBox width="100%">
					<mx:Label text="Preis:" width="100" />
					<mx:Spacer width="20" />
					<mx:TextInput id="neueLeistungPreis" width="100%" />								
				</mx:HBox>
				<mx:Spacer height="100%" />
				<mx:Button label="+" click="neueLeistung.send(); neueLeistungName.text=''; neueLeistungPreis.text=''" />
			</mx:VBox>
		</mx:VBox>
	
	<!--   Produkte   -->
			
		<mx:VBox label="Produkte" height="100%" width="100%"  paddingLeft="8" paddingTop="8" paddingRight="8" paddingBottom="8" backgroundColor="#f8f8f8" borderColor="#e0e0e0" borderThickness="1" borderStyle="solid">
			<mx:Text text="Produkte" fontWeight="bold" fontSize="14" color="#3D98FF"/>
			<mx:DataGrid variableRowHeight="true" editable="true" height="100%" itemEditEnd="updateProdukt(event)" id="produkteGrid" wordWrap="true" dataProvider="{produkteListe.lastResult.produkte.produkt}" width="100%">
				<mx:columns>
					<mx:DataGridColumn dataField="ID" editable="false" width="30"  />
					<mx:DataGridColumn dataField="Kategorie" />
			        <mx:DataGridColumn dataField="Artikelnummer" width="60" />
			        <mx:DataGridColumn dataField="Bezeichnung" />
			        <mx:DataGridColumn dataField="Inhalt" />
			        <mx:DataGridColumn dataField="VE" width="30" textAlign="right" />
			        <mx:DataGridColumn dataField="EK" width="50" textAlign="right" labelFunction="formatPreis" />
			        <mx:DataGridColumn dataField="VK" width="50" textAlign="right" labelFunction="formatPreis" />
			        <mx:DataGridColumn dataField="Vorrat" width="50" textAlign="right" />
			        <mx:DataGridColumn dataField="Verkauf" itemRenderer="com.renderers.dataGridCheckBox" rendererIsEditor="true" width="60" textAlign="center" />
				</mx:columns>
			</mx:DataGrid>
			<mx:HBox width="100%">
				<mx:Label text="(EK) Waren im Gesamtwert von"  fontWeight="bold"/>
				<mx:Label id="sumEK"  fontWeight="bold"/>
				<mx:Spacer width="100%" />
				<mx:Button label="-" click="loescheProdukt.send()" />
			</mx:HBox>
			<mx:VBox width="100%" height="160" paddingTop="10" horizontalAlign="left" verticalAlign="bottom">
				<mx:Text text="Neues Produkt" fontWeight="bold" width="100%"/>
					<mx:HBox width="90%" height="100%">
						<mx:VBox width="260">
							<mx:HBox width="100%">
								<mx:Label text="Bezeichnung:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktBezeichnung" width="160" />
							</mx:HBox>
							<mx:HBox width="100%">
								<mx:Label text="Kategorie:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktKategorie" width="160" />								
							</mx:HBox>
							<mx:HBox width="100%">
								<mx:Label text="Inhalt:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktInhalt" width="160"  />
							</mx:HBox>
						</mx:VBox>
						<mx:Spacer width="15" />
						<mx:VBox width="140">
							<mx:HBox width="100%">
								<mx:Label text="A-Nr.:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktArtikelnummer" width="80" />								
							</mx:HBox>
							<mx:HBox width="100%">
								<mx:Label text="EK:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktEK" width="80"  />
							</mx:HBox>
							<mx:HBox width="100%">
								<mx:Label text="VK:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktVK" width="80" />
							</mx:HBox>
						</mx:VBox>
						<mx:Spacer width="15" />
						<mx:VBox width="130">
							<mx:HBox width="100%">
								<mx:Label text="VE:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktVE" width="50" />								
							</mx:HBox>
							<mx:HBox width="100%">
								<mx:Label text="Vorrat:" />
								<mx:Spacer width="100%" />
								<mx:TextInput id="neuesProduktVorrat" width="50"  />
							</mx:HBox>
							<mx:HBox width="100%">
								<mx:Label text="zum Verkauf:" />
								<mx:Spacer width="100%" />
								<mx:CheckBox id="neuesProduktForSale" selected="false" />
							</mx:HBox>
						</mx:VBox>
					</mx:HBox>
					
						
						
						<mx:Button label="+" 
							click=" neuesProdukt.send(); 
									neuesProduktKategorie.text=''; 
									neuesProduktArtikelnummer.text='';
									neuesProduktBezeichnung.text='';
									neuesProduktInhalt.text='';
									neuesProduktVE.text='';
									neuesProduktEK.text='';
									neuesProduktVK.text='0.00';
									neuesProduktVorrat.text='';
									neuesProduktForSale.selected=false;" 
						/>
				</mx:VBox>
		</mx:VBox>

Open in new window

Error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at verwaltung/calcSumEK()[/Users/XXX/Documents/Flex Builder 3/Kundenverwaltung/src/verwaltung.mxml:167]
	at verwaltung/__produkteListe_result()[/Users/XXX/Documents/Flex Builder 3/Kundenverwaltung/src/verwaltung.mxml:239]
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\mxml\HTTPService.as:290]
	at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193]
	at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
	at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
	at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403]
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at flash.net::URLLoader/onComplete()

Open in new window

0
druplash
Asked:
druplash
1 Solution
 
zzynxSoftware engineerCommented:
What's in the file "verwaltung.mxml" at line 167? Can you post it?
There you have an object that is null where your code doesn't expect it.
0
 
Gary BenadeCommented:
Hi Druplash

Your script is accessing a tab navigator page before it has been created. By default the tabNavigator component only creates children as then are needed (deferred instantiation)

You can change the behavior and create all children by specifying the creationPolicy:

<mx:TabNavigator width="100%" height="100%" id="nav2" selectedIndex="0"  creationPolicy="all">

Regards
Gary
0
 
druplashAuthor Commented:
Thanks a lot, that works perfect and now i understand the issue.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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