Solved

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

Posted on 2011-02-17
12
2,217 Views
Last Modified: 2012-05-11
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
Comment
Question by:mebibyte
  • 6
  • 6
12 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34923276
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
 

Author Comment

by:mebibyte
ID: 34931588
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
 

Author Comment

by:mebibyte
ID: 34931598
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
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34931622
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
 

Author Comment

by:mebibyte
ID: 34939717
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
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34940000
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:mebibyte
ID: 34940040
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
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34940145
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
 

Author Comment

by:mebibyte
ID: 34940243
<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
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
ID: 34940300
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
 

Author Comment

by:mebibyte
ID: 34947111
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
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34948345
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

22 Experts available now in Live!

Get 1:1 Help Now