Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-17
12
Medium Priority
?
2,281 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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
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
 

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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

971 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