Flex. pushView data Object being converted into a String - actionscript-3

After executing a navigator.pushView with data object, I'm in need of the data object to be received into the next view, but at some stage transformed into a string to use in a sql function.
The code below shows what I'm working on at the moment.
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="{data.toString()}"
xmlns:model="model.*"
creationComplete = "{data=srv.findByCategory(data.toString())}"
>
.toString() was my quick attempt at it, but the resultant output is simply
[object Object]
There aren't any errors but it only shows during debug.
Any ideas?
As appendage, here is the code from the initial view where the data object originates from
<s:List id="list" top="0" bottom="0" left="0" right="0" width="100%"
alternatingItemColors="0xffffff"
contentBackgroundColor="0xffffff"
downColor="0xfc7d1a"
selectionColor="0xfc7d1a"
dataProvider="{data}"
labelFunction="getFullName"
change="navigator.pushView(CategoryView, list.selectedItem.toString())">
And here is some of the code which needs the data object to be a String.
public function findByCategory(searchKey:String):ArrayCollection
{
}

data is a keyed object containing containing the info you passed from the initial view. You need to access the correct key in your object.
It should be something like data.myKey.toString(). I would be able to tell you exactly if you paste your pushView code.

Related

How to use Non-assignment expressions in Flex as3 using Flex SDK?

I was looking in to ActionScript 3 Specification in that i noticed Non-assignment expressions under index -> 14 Expressions > 14.18 Non-assignment expressions. Is it possible to assign data type for a variable dynamically through ternary operator ?: like below as mentioned in docx..
A NonAssignmentExpression may be used where ever a TypeExpression may be used.
var x : hintString ? String : Number
If its is possible in as3 when i build this using flex SDK i got Syntax Error
> src\App.mxml(29): Error: Syntax error: expecting semicolon before String.
var x1: h1 ? String : Number;
for the below code.
<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="onComplete()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function onComplete():void
{
//test
var h1:String = 'hai';
var x1: h1 ? String : Number;
Alert.show("Type of x1 :"+typeof(x1));
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
</s:Application>
If it is possible in as3 and why not in Flex ? I have checked in Adobe docs on conditional operator but nothing is mentioned there like the above why?
Interesting question. What you've written there is ActionScript 3.0 so the construct isn't possible regardless of whether you're writing pure ActionScript 3.0 or ActionScript 3.0 within a Flex context. I've worked with the language since it was born and I've never seen that construct before.
My best guess is that it must be an error in the AS 3.0 specification document. There's nothing about it in the proposed Proposed ECMAScript 4th Edition – Language Overview document and this Mozilla Tamarin bug report page says it's (quote) "not implemented nor implementable".
As a side-note, I'm struggling to think of an application for this construct.
Yes, really interesting question, thanks for pointing it.
I tried:
var h1:String = null; //(if try var h1:String = 'hai' the output will be [class String]
var x1 = h1 ? String : Number;
// probably the same result as x1:*
trace(x1); // [class Number]
I just checked the abc of this test and when we use this approach or *, it uses coerce_a (Indicates to the verifier that the value on the stack is of the any type ( * ). Does nothing to value.)
I agree with #net.uk.sweet, about struggling to think of an application for this construct..

(Flex & actionscript 3) convert result in datagrid control to json data

i want to convert the result in spark datagrid cotrol to json data
i'm using actionscript 3 and Flex
this is my datagrid :
<s:DataGrid id="_gridcentre" left="5" right="5" top="5" bottom="5"
borderVisible="true" dataProvider="{GetCentreResult.lastResult}"
fontSize="11">
<s:columns>
<s:ArrayList>
<s:GridColumn visible="false" dataField="Codecentre"headerText="Code"/>
<s:GridColumn dataField="Nomcentre" headerText="Nom Centre"/>
<s:GridColumn dataField="Typecentre" headerText="Type Centre"/>
<s:GridColumn dataField="Milieurecepteur" headerText="Milieu Récepteur"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
i did this code, but it not working :
var result:Object = _gridcentre.dataProvider as Object;
var myJson:String = JSON.stringify(result);
i can read my objects, when i iterate my object < result > like this :
for each (var item:Centre in result)
{
Alert.show(item.Codecentre.toString());
}
thanks for help
The dataprovider is usually an instance of a array alike class.
Most likely spark's ArrayList or ArrayCollection class instance, which means that You can try toArray() method, which will return the raw objects contaned into, or if this fail - try to find the type of the data provider and invoke it's appropriate method to convert contained objects into array or some other structure which you can iterate trough.
h1! GetCentreResult.lastResult -> typeof() ?

Bind data of custom object to TextView in MvvmCross

I have one custom object in my ViewModel.I want to bind only one of its member to textview in my droid view.
I want to bind only string member of that object to textview
Currently I am doing this.
local:MvxBind = "Text Myobject.ItsMember"
Is it ok?
Or am I wrong?
Or Can I do Like this?
local:MvxBind = "ItemsSource MyObject ; Text ItsMember"
How can I achieve this?
local:MvxBind = "Text MyObject.ItsMember" is perfectly fine. Just make sure your spelling and capitalization are correct. Also, ItsMember should be a string or have a valid value returned as ToString.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Text MyObject.ItsMember"
/>

how to retrieve data from database using flex code

I want to display the values coming from database in a datagrid using flex. Here is my code. I am using webservice. I have database values from application1_initializeHandler() method. How to fetch these values into onResult() method and perform databinding? I want code for onResult() function and data binding. Please help..
<?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" initialize="application1_initializeHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
protected function application1_initializeHandler(event:FlexEvent):void
{
AreasOfWestBengal.loadWSDL();
var s:String = "SELECT * FROM [CSFTestNew].[dbo].[AreasOfWestBengal]";
var t:AsyncToken = AreasOfWestBengal.GetRec("[AreasOfWestBengal]", s, "1", "SQLExpress");
t.addResponder(new AsyncResponder(onResult, onFault, t));
}
protected function onResult(event:ResultEvent, token:Object=null):void
{
}
protected function onFault(event:FaultEvent, token:Object=null):void
{
trace(event.fault.toString());
}
]]>
</fx:Script>
<fx:Declarations>
<s:WebService id="AreasOfWestBengal" wsdl="https://www.geoviewer8.com/gv8webservices/CSF_NewGVOConfig/GVOConfig.asmx?wsdl"/>
</fx:Declarations>
<mx:DataGrid x="197" y="83" width="348" height="216">
<mx:columns>
<mx:DataGridColumn headerText="Areas" dataField="Areas"/>
<mx:DataGridColumn headerText="SubAreas" dataField="SubAreas"/>
</mx:columns>
</mx:DataGrid>
</s:Application>
Thanks
One solution would be to set a data provider (like an ArrayCollection) for your mx:DataGrid as its dataProvider attribute - see the Passing Data to a DataGrid Control section here for an example.
Now, when your onResult function executes, you probably want to first clear out your data provider (remove any rows from your DataGrid) - if the data source is an ArrayCollection, you would use the removeAll method. Now obtain the actual web service call result from the ResultEvent parameter (in your code, it is event.result). You need to know the data type of this result value (it should be some kind of list data structure) so that you can figure out how to add its elements into the DataGrid's data provider as rows of the grid. For example, if your data provider is an ArrayCollection, you can add each element of event.result into this ArrayCollection using its addItem method. If event.result implements the IList interface, you could add all rows into the data provider using the addAll method of ArrayCollection. Make sure that the objects that you add into the data provider as the rows conform to your mx:DataGridColumns - i.e. these objects need to have Areas and SubAreas properties so that their values will be displayed in these columns.
Here is a web service-specific DataGrid example from Adobe.
protected function onResult(event:ResultEvent, token:Object=null):void
{
// Assuming the grid's data provider is an ArrayCollection
// (1) clear existing table rows
dataProvider.removeAll();
// (2) add the new rows from event.result into dataProvider
// using dataProvider.addAll(event.result) if possible or one at a time
// using dataProvider.addItem(...)
dataProvider.addAll(event.result);
// An alternative to the above would be to replace the dataProvider
// of your grid with event.result if it is a compatible data type
// AreasOfWestBengal.dataProvider = event.result;
}

Flex xml in tree

The following xml values is getting from php file
<result>
<list>
<node>air</node>
<node>flex</node>
<node>android</node>
</list>
</result>
i am calling this xml using httpservice
<mx:HTTPService
id="project"
url="http://localhost/eshpm/AIR/newproject.php"
method="POST" result="onResult_projectname(event)" resultFormat="e4x">
<mx:request xmlns="">
<name>yes</name>
</mx:request>
</mx:HTTPService>
The result is obtained using the function
private function onResult_projectname(evt:ResultEvent):void
{
xmldata = new XML(evt.result);
xmlList_user = new XMLListCollection(xmldata.list);
tree.dataProvider = xmlList_user.children();
}
The problem is that i am able to display the values in Tree.......but it is repeating
ie, "air" is comming in tree twice....
plz help.............thanks
Try using <mx:Tree dataProvider="{project.lastResult.result}" labelField="node"/>. By invoking project.send() databinding works and populates your Tree.