arraycollection error in flex4.6 - json

I'm having difficulty passing json to a datagrid.
I get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection#bc292a9 to Array.
at Function/<anonymous>()[C:\Users\Birger\Dropbox\Rich Media Applications\P006_Project\src\FULLTEST.mxml:10]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.binding::Binding/wrapFunctionCall()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:395]
at mx.binding::Binding/innerExecute()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:469]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.binding::Binding/wrapFunctionCall()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:395]
at mx.binding::Binding/execute()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:333]
at mx.binding::BindingManager$/executeBindings()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\BindingManager.as:153]
at FULLTEST/_FULLTEST_ArrayCollection1_i()[C:\Users\Birger\Dropbox\Rich Media Applications\P006_Project\src\FULLTEST.mxml:4]
at FULLTEST()[C:\Users\Birger\Dropbox\Rich Media Applications\P006_Project\src\FULLTEST.mxml:4]
my code is:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:components="components.*" initialize="getData.send();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:HTTPService id="getData" url="http://localhost/P006_Project/Query.php"
useProxy="false" method="POST" resultFormat="text" result="getPHPData(event)">
</mx:HTTPService>
<s:ArrayCollection id="acItems" source="{dataArray}" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
[Bindable]private var dataArray:ArrayCollection = new ArrayCollection();
private function initDataGrid():void
{
getData.send();
}
private function getPHPData(event:ResultEvent):void
{
var rawArray:Array;
var rawData:String = String(event.result);
rawArray = JSON.parse(rawData) as Array;
dataArray = new ArrayCollection(rawArray);
}
]]>
</fx:Script>
<mx:Accordion id="accItems" creationPolicy="auto">
<s:NavigatorContent label="Frisdranken">
<components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
</s:NavigatorContent>
</mx:Accordion>
</s:Application>
so I'm trying to fill my datagrid with content from my database by converting it into JSON. I'm using a custom component (just an ordinary datagrid in this one).

Here is the problem:
<s:ArrayCollection id="acItems" source="{dataArray}" />
source needs to be of type "Array" but you're assigning the source to an ArrayCollection object.
You should do:
<s:ArrayCollection id="acItems" source="{dataArray.source}" />
Hope this helps.

Related

"null object reference" error in ActionScript 3

I used my app's resize handler to resize my component but it is throwing this error :
TypeError: Error #1009: Cannot access a property or method of a null object reference
Here is my code :
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
resize="application2_resizeHandler(event)" >
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
private var employeeName:String = 'ravi';
protected function application2_resizeHandler(event:ResizeEvent):void
{
mainGroup.width = stage.width - 10;
mainGroup.x = 5;
}
]]>
</fx:Script>
<s:Group width="100%" height="100%">
<s:VGroup id="mainGroup" >
<s:Label id="employeeNameLabel" text="{employeeName}" />
<s:Label id="departmentLabel" />
</s:VGroup>
<s:Button id="getData" />
</s:Group>
</s:Application>
You got the #1009 error because your resize event is fired before the creation of your objects. So, you should wait for that and that your app is added to the stage to be able to use the stage object.
For that, I think that the best event is the applicationComplete event, then you can add a resize event to resize your component ...
So you can do like this for example :
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
applicationComplete="application2_applicationCompleteHandler(event)" >
then
protected function application2_applicationCompleteHandler(event:FlexEvent):void
{
// if you want you can resize your component for the 1st time
// by calling the application2_resizeHandler() function
application2_resizeHandler(new ResizeEvent(ResizeEvent.RESIZE));
// add the resize event listener to your app
event.target.addEventListener(ResizeEvent.RESIZE, application2_resizeHandler);
}
Hope that can help.

TypeError: Error #1034: Type Coercion failed: cannot convert views::AGISHomeView#6396ae1 to spark.components.View

I am new to flex, and Flash builder, I followed the tutorial in this link: Query your data to write a mobile mapping application that includes a query task, after writing the code, no errors appeared in the problems tab but there was 6 warnings, and when running the app the following error appears:
An ActionScript error has occurred:
TypeError: Error #1034: Type Coercion failed: cannot convert views::AGISHomeView#6396ae1 to spark.components.View.
at spark.components::ViewNavigator/createViewInstance()[E:\dev\4.y\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1999]
at spark.components::ViewNavigator/commitNavigatorAction()[E:\dev\4.y\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1932]
at spark.components::ViewNavigator/commitProperties()[E:\dev\4.y\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1301]
at mx.core::UIComponent/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:8219]
at mx.managers::LayoutManager/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:783]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]”
Any kind of help is appreciated.
Hani,
Here is the code I used:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns="http://ns.adobe.com/air/application/4.6"
xmlns:esri="http://www.esri.com/2008/ags">
<s:layout>
<s:VerticalLayout gap="10"
horizontalAlign="center"
paddingBottom="20"
paddingLeft="25"
paddingRight="25"
paddingTop="20"/>
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.FeatureSet;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
private function doQuery():void
{
queryTask.execute(query, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
// No code needed in this simple sample, since the
// graphics layer is bound to the query result using
// graphicProvider="{queryTask.executeLastResult.features}"
}
function onFault(info:Object, token:Object = null):void
{
Alert.show(info.toString(), "Query Problem");
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Layer with US States -->
<esri:QueryTask id="queryTask"
showBusyCursor="true"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"
useAMF="false"/>
<esri:Query id="query"
outSpatialReference="{myMap.spatialReference}"
returnGeometry="true"
text="{qText.text}">
<esri:outFields>
<fx:String>MED_AGE</fx:String>
<fx:String>POP2007</fx:String>
</esri:outFields>
</esri:Query>
</fx:Declarations>
<s:Panel height="60"
backgroundColor="0xB2BFC6"
title="Query a layer (search for a state)">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:TextInput id="qText"
width="100%"
enter="doQuery()"
text="California"/>
<s:Button click="doQuery()" label="Do Query"/>
</s:Panel>
<esri:Map id="myMap">
<esri:extent>
<esri:Extent xmin="-14298000" ymin="2748000" xmax="-6815000" ymax="7117000">
<esri:SpatialReference wkid="102100"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer
url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/>
</esri:Map>
</s:Application>
_______________________________________________________________
I tried your code and its working fine for me with no warning. Can you show what all are the warning your are getting? I think those should be related to skin and you have ti change RSL setting to make it work.
Change RSL setting for Arcgis.swc to 'EXternal'

Flex reference child element

How can we reference to an element which is added dynamically on runtime?
Example code:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function init(event:FlexEvent):void
{
// TODO Auto-generated method stub
trace(button1.label);
var newbtn:Button = new Button();
newbtn.label = "New Button";
newbtn.id = "button3";
newbtn.name = "button3";
mygroup.addElement(newbtn);
trace(this["button3"].label);
}
]]>
</fx:Script>
<s:HGroup id="mygroup">
<s:Button id="button1" label="Button 1" />
<s:Button id="button2" label="Button 2" />
</s:HGroup>
</s:WindowedApplication>
When I try to run above code, it dispatch error
Error #1069: Property button3 not found on project1 and there is no default value.
So, how can I call to the newly added button?
Store your instance in a variable and reference it whenever you feel like it. Use an array for a list of variables.
you can try using
var obj = this.getChildByName("button3");
after that you can use obj to trace the label

Binding is not happening on Object Property and text Input

I am trying bind an Object property value to a text field. (Well I have taken this as an example ... I have no.of form fields and to be bound by other values)
But when change its value on button click the text field is not getting updated?
Below is the example code,
<?xml version="1.0" encoding="utf-8"?>
<s:Application
minHeight="600"
minWidth="955"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
[Bindable]
var currentFormItem:Object = new Object();
public function changeName():void
{
currentFormItem.name = "hello";
}
]]>
</fx:Script>
<s:HGroup>
<s:TextInput id="test"
text="{currentFormItem.name}"/>
<s:Button click="changeName()"/>
</s:HGroup>
Thanks
I got the solution for this. I can just wrap this object in ObjectProxy.

Flex Hbox Creation complete not invoked

I am trying to create an instance of Hbox like
obj = new HBox();
disp.addElement(obj); // disp object is border container but obj is mx component
this is the way I have been using a display object is adding to a parent container .
But it doesn't invoke the creation complete event.
I have been working on this last few days. Please help me.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" initialize="windowedapplication1_initializeHandler(event)">
<fx:Script>
<![CDATA[
import flash.sampler.NewObjectSample;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function windowedapplication1_initializeHandler(event:FlexEvent`enter code here`):void
{
var hbo:HBox=new HBox();
hbo.addEventListener(FlexEvent.CREATION_COMPLETE,ff);
b.addElement(hbo);
}
public function ff(e:FlexEvent):void
{
Alert.show("created")
}
]]>`enter code here`
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Group id="b">
</s:Group>
</s:WindowedApplication>