mebibyte
asked on
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.
XML File [ Named: chartInfo.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>
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>
ASKER
Thanks, this cleared up that error but now..
ERROR: 1120: Access of undefined property srv. line 7
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]
ERROR: 1120: Access of undefined property srv. line 7
ASKER
I removed from line 7 and thew no errors but when I ran it - the data didnt show.
;srv.send();
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
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
ASKER
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>
Try this way instead of the model:
Deepanjan Das
<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" />
Warm RegardsDeepanjan Das
ASKER
excellent !
no more errors but when compiled
tried changing "Additional Compiler Arguments:
from: -locale en_US
to
-use-network=false
still same error.
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]
tried changing "Additional Compiler Arguments:
from: -locale en_US
to
-use-network=false
still same error.
Add this:
Warm Regards
Deepanjan Das
<mx:HTTPService id="srv" resultFormat="e4x" result="xmlHandler(event)" fault="onFault(event)" useProxy="false"/>
private function onFault(event:FaultEvent):void{
//on error
}
Warm Regards
Deepanjan Das
ASKER
<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>
Parse error: 'private function onFault(event:FaultEvent):
' is not allowed to follow '</mx:HTTPService>'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Compiled successfully with no errors but data is not loading.
chartInfo.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();" 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>
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.
picFlex4.JPG
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
Warm Regards
Deepanjan Das
Open in new window
Now update the function xmlHandler() to this:
Open in new window
Warm Regards
Deepanjan Das
Open in new window