Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

 
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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

719 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