Solved

private function works only without TabNavigator?

Posted on 2014-09-07
3
284 Views
Last Modified: 2014-09-08
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
Comment
Question by:druplash
3 Comments
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
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
 
LVL 19

Accepted Solution

by:
Gary Benade earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:druplash
Comment Utility
Thanks a lot, that works perfect and now i understand the issue.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now