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

Error: Implicit coercion of a value with static type Object to a possibly unrelated type XMLList

Still trying to get this example to work with xml.

<s:Application 
	xmlns:fx="http://ns.adobe.com/mxml/2009" 
	xmlns:mx="library://ns.adobe.com/flex/mx" 
	xmlns:s="library://ns.adobe.com/flex/spark" 
	creationComplete="initApp();srv.send();"
	height="600">
	
	<fx:Declarations>
 
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
		import mx.rpc.events.ResultEvent;
		public var initSeriesArray:Array = new Array();
		public var level:Number = 1;
		public var newSeries:Array;
				

		[Bindable]
		private var chartInfo:XMLList;
		
		private function xmlHandler(evt:ResultEvent):void{
			//Sets chartInfo's root as data. Everything else referenced in respect to this.
			chartInfo = evt.result;
		}
									
		private function initApp():void {
			// Get initial series Array -- to be reloaded when it returns 
			// from a drill down.
			initSeriesArray = chart.series;             
		}
		
		private function zoomIntoSeries(e:Event):void {
			newSeries = new Array();
			if (level == 1) {
				newSeries.push(e.currentTarget);   
				level = 2; 
			} else {
				newSeries = initSeriesArray;
				p1.title = "Net Worth";
				level = 1;
			}           
			chart.series = newSeries;            
		}
		
	]]></fx:Script>
	
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	
	<s:Panel id="p1" title="Net Worth">
		<s:layout>
			<s:VerticalLayout/>
		</s:layout>
		<mx:ColumnChart id="chart" dataProvider="{chartInfo}" type="stacked" showDataTips="true">
			<mx:series> 
				<mx:ColumnSeries id="s1" 
								 displayName="Cash" 
								 yField="cash" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s2" 
								 displayName="Stocks" 
								 yField="stocks"  
								 xField="date"  
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s3" 
								 displayName="Retirement" 
								 yField="retirement" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s4" 
								 displayName="Home" 
								 yField="home" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s5" 
								 displayName="Other" 
								 yField="other" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
			</mx:series>            
			<mx:horizontalAxis >
				<mx:DateTimeAxis title="Date" dataUnits="months"/>
			</mx:horizontalAxis>    
		</mx:ColumnChart> 
		<mx:Legend dataProvider="{chart}"/>
	</s:Panel>
</s:Application>

Open in new window



XML File [ Named: chartInfo.xml]
<?xml version="1.0" encoding="UTF-8"?>
<data>
	<months>1/1/2008</months>
	<cash>50500</cash>
	<stocks>198192</stocks>
	<retirement>130101</retirement>
	<home>75000</home>
	<other>19148</other>
	<assets>472941</assets>
	
	<months>2/1/2008</months>
	<cash>51000</cash>
	<stocks>201042</stocks>
	<retirement>135000</retirement>
	<home>75300</home>
	<other>19148</other>
	<assets>481590</assets>
	
	<months>3/1/2008</months>
	<cash>51550</cash>
	<stocks>206510</stocks>
	<retirement>13700</retirement>
	<home>75600</home>
	<other>19348</other>
	<assets>490008</assets>

</data>

Open in new window



0
mebibyte
Asked:
mebibyte
  • 6
  • 6
1 Solution
 
deepanjandasCommented:
Can you please change your xml to this format:
<?xml version="1.0" encoding="UTF-8"?>
<data>
    <set>
        <months>1/1/2008</months>
        <cash>50500</cash>
        <stocks>198192</stocks>
        <retirement>130101</retirement>
        <home>75000</home>
        <other>19148</other>
        <assets>472941</assets>
    </set>
    <set>
        <months>2/1/2008</months>
        <cash>51000</cash>
        <stocks>201042</stocks>
        <retirement>135000</retirement>
        <home>75300</home>
        <other>19148</other>
        <assets>481590</assets>
    </set>
    <set>
        <months>3/1/2008</months>
        <cash>51550</cash>
        <stocks>206510</stocks>
        <retirement>13700</retirement>
        <home>75600</home>
        <other>19348</other>
        <assets>490008</assets>
    </set>
</data>

Open in new window


Now update the function xmlHandler() to this:
<?xml version="1.0" encoding="UTF-8"?>
<data>
    <set>
        <months>1/1/2008</months>
        <cash>50500</cash>
        <stocks>198192</stocks>
        <retirement>130101</retirement>
        <home>75000</home>
        <other>19148</other>
        <assets>472941</assets>
    </set>
    <set>
        <months>2/1/2008</months>
        <cash>51000</cash>
        <stocks>201042</stocks>
        <retirement>135000</retirement>
        <home>75300</home>
        <other>19148</other>
        <assets>481590</assets>
    </set>
    <set>
        <months>3/1/2008</months>
        <cash>51550</cash>
        <stocks>206510</stocks>
        <retirement>13700</retirement>
        <home>75600</home>
        <other>19348</other>
        <assets>490008</assets>
    </set>
</data>

Open in new window


Warm Regards
Deepanjan Das
private function xmlHandler(evt:ResultEvent):void{
    //Sets chartInfo's root as data. Everything else referenced in respect to this.
    chartInfo = evt.result.set;
}

Open in new window

0
 
mebibyteAuthor Commented:
Thanks, this cleared up that error but now..

1     <?xml version="1.0" encoding="utf-8"?>
2    <s:Application 
3	xmlns:fx="http://ns.adobe.com/mxml/2009" 
4	xmlns:mx="library://ns.adobe.com/flex/mx" 
5	xmlns:s="library://ns.adobe.com/flex/spark" 
6	creationComplete="initApp();srv.send();"
[b]7	height="600">[/b]

Open in new window


ERROR: 1120: Access of undefined property srv.      line 7      
0
 
mebibyteAuthor Commented:
I removed from line 7 and thew no errors but when I ran it - the data didnt show.

;srv.send();

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
deepanjandasCommented:
srv might be a HTTP Handler for fetching the xml data which is missing,

So add a HTTP handler with the id as srv, and the source path to that of the xml.

Also keep the srv.send in where it was and you should be done.

Warm Regards
Deepanjan Das
0
 
mebibyteAuthor Commented:
i added fx model still same error

<s:Application 
	xmlns:fx="http://ns.adobe.com/mxml/2009" 
	xmlns:mx="library://ns.adobe.com/flex/mx" 
	xmlns:s="library://ns.adobe.com/flex/spark" 
	creationComplete="initApp();srv.send();">
	
	<fx:Declarations>
		<fx:Model id="info1" source="chartInfo.xml"/>
	</fx:Declarations>

Open in new window

0
 
deepanjandasCommented:
Try this way instead of the model:
<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" />

Open in new window

Warm Regards
Deepanjan Das
0
 
mebibyteAuthor Commented:
excellent !

no more errors but when compiled

[RPC Fault faultString="A URL must be specified with useProxy set to false." faultCode="Client.URLRequired" faultDetail="null"]


at mx.rpc.http::AbstractOperation/sendBody()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\http\AbstractOperation.as:871]

at mx.rpc.http::HTTPService/send()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:880]

at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]

at mx.core::UIComponent/set initialized()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1577]
	
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
	
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.0.0\framew<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" />orks\projects\framework\src\mx\managers\LayoutManager.as:1072]

Open in new window


tried changing "Additional Compiler Arguments:

from: -locale en_US  

to

-use-network=false

still same error.
0
 
deepanjandasCommented:
Add this:
 
<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" fault="onFault(event)" useProxy="false"/>

private function onFault(event:FaultEvent):void{
    //on error
}

Open in new window


Warm Regards
Deepanjan Das
0
 
mebibyteAuthor Commented:
<fx:Declarations>

<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" fault="onFault(event)"  useProxy="false"/>
private function onFault(event:FaultEvent):void{
//on error
}

</fx:Declarations>

Open in new window



Parse error: 'private function onFault(event:FaultEvent):void{//on error}
      ' is not allowed to follow '</mx:HTTPService>'.






0
 
deepanjandasCommented:
private function onFault(event:FaultEvent):void{
//on error
}

This is a function and should be in script tag, place this below the xmlHandler() function.

Rest is fine
0
 
mebibyteAuthor Commented:
Compiled successfully with no errors but data is not loading.

<s:Application 
	xmlns:fx="http://ns.adobe.com/mxml/2009" 
	xmlns:mx="library://ns.adobe.com/flex/mx" 
	xmlns:s="library://ns.adobe.com/flex/spark" 
	creationComplete="initApp();srv.send();" width="700">
	
	<fx:Declarations>
		<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" fault="onFault(event)" useProxy="false"/>
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
		public var initSeriesArray:Array = new Array();
		public var level:Number = 1;
		public var newSeries:Array;
				
		//XML List for loaded XML file. Must be bindable!
		[Bindable]
		private var chartInfo:XMLList;
		
			private function xmlHandler(evt:ResultEvent):void{
				//Sets chartInfo's root as data. Everything else referenced in respect to this.
				chartInfo = evt.result.set;
			}
			private function onFault(event:FaultEvent):void{
			
			}
									
		private function initApp():void {
			// Get initial series Array -- to be reloaded when it returns 
			// from a drill down.
			initSeriesArray = chart.series;             
		}
		
		private function zoomIntoSeries(e:Event):void {
			newSeries = new Array();
			if (level == 1) {
				newSeries.push(e.currentTarget);   
				level = 2; 
			} else {
				newSeries = initSeriesArray;
				p1.title = "Net Worth";
				level = 1;
			}           
			chart.series = newSeries;            
		}
			
	]]>
		
	</fx:Script>

	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	
	<s:Panel id="p1" title="Net Worth">
		<s:layout>
			<s:VerticalLayout/>
		</s:layout>
		<mx:ColumnChart id="chart" dataProvider="{chartInfo}" type="stacked" showDataTips="true">
			<mx:series> 
				<mx:ColumnSeries id="s1" 
								 displayName="Cash" 
								 yField="cash" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s2" 
								 displayName="Stocks" 
								 yField="stocks"  
								 xField="date"  
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s3" 
								 displayName="Retirement" 
								 yField="retirement" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s4" 
								 displayName="Home" 
								 yField="home" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s5" 
								 displayName="Other" 
								 yField="other" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
			</mx:series>            
			<mx:horizontalAxis >
				<mx:DateTimeAxis title="Date" dataUnits="months"/>
			</mx:horizontalAxis>    
		</mx:ColumnChart> 
		<mx:Legend dataProvider="{chart}"/>
	</s:Panel>
</s:Application>

Open in new window






chartInfo.xml
<?xml version="1.0" encoding="UTF-8"?>
<data>
    <set>
        <months>1/1/2008</months>
        <cash>50500</cash>
        <stocks>198192</stocks>
        <retirement>130101</retirement>
        <home>75000</home>
        <other>19148</other>
        <assets>472941</assets>
    </set>
    <set>
        <months>2/1/2008</months>
        <cash>51000</cash>
        <stocks>201042</stocks>
        <retirement>135000</retirement>
        <home>75300</home>
        <other>19148</other>
        <assets>481590</assets>
    </set>
    <set>
        <months>3/1/2008</months>
        <cash>51550</cash>
        <stocks>206510</stocks>
        <retirement>13700</retirement>
        <home>75600</home>
        <other>19348</other>
        <assets>490008</assets>
    </set>
    <set>
        <months>4/1/2008</months>
        <cash>51590</cash>
        <stocks>206900</stocks>
        <retirement>13790</retirement>
        <home>75690</home>
        <other>19390</other>
        <assets>490098</assets>
    </set>
        <set>
        <months>5/1/2008</months>
        <cash>51790</cash>
        <stocks>206999</stocks>
        <retirement>13800</retirement>
        <home>75860</home>
        <other>19690</other>
        <assets>490900</assets>
    </set>
     <set>
        <months>6/1/2008</months>
        <cash>51990</cash>
        <stocks>207999</stocks>
        <retirement>13900</retirement>
        <home>75960</home>
        <other>19990</other>
        <assets>490990</assets>
    </set>
         <set>
        <months>7/1/2008</months>
        <cash>52990</cash>
        <stocks>217999</stocks>
        <retirement>14900</retirement>
        <home>76960</home>
        <other>19999</other>
        <assets>490999</assets>
    </set>
</data>


attached is a pic when compiled.

Open in new window

picFlex4.JPG
0
 
deepanjandasCommented:
The process is correct, just check whether the chartInfo object is compatible as the ColumnChart dataprovider. I will try to check your code today and will update you.

Warm Regards
Deepanjan Das
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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