Link to home
Start Free TrialLog in
Avatar of mokatell
mokatell

asked on

arraycollection with dataproviders

dear experts ,
i have been facing this problem since a period of time .
i have a list with ID="abc"  and dataprovider="{arrayCollection}" .... the problem is when i have an arrayCollection with one record , the list remains empty unless the arrayCollection items are 2 and above ... then the list gets the items .. i have the same problem with datagrid ... as i said only when i retrieving one record !!! any suggested solution ..
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Just do abc.validate(); once you assign.

To do that change your code to ID="abc"  click="somefunction()";

inside that do abc.dataprovider=arrayCollection; and then do abc.validate();
Avatar of mokatell
mokatell

ASKER

didnt work !
can u show the code?
as simple as it is :

<s:HTTPService id="getVersions" url="{commonMethods.URLlink+'getVersions.php'}" method="POST" showBusyCursor="true" result="getVersions_resultHandler(event)" />


protected function getVersions_resultHandler(event:ResultEvent):void
{
versionsArray = getVersions.lastResult.tasks.first as ArrayCollection ;
OR
abc.dataprovider = getVersions.lastResult.tasks.first as ArrayCollection

BOTH DIDN'T WORK
                  
}


<s:List id="abc" dataProvider="{versionsArray}"/>
Problem can be on the server side if you declared for example result as single object AMF encoder will convert to Object if you will pass List of object it will convert to ArrayCollection
<?php
session_start();
header ("Cache-control:private");
include "phpConnect.php";

$qry = "select * from checkver";
$res = mysql_query ($qry) or die (mysql_error());

echo "<tasks>" ;
while ( $info=mysql_fetch_array($res))
{
echo "<first> <ptitle>$info[0]</ptitle> <ptype>$info[1]</ptype></first>";
}
echo "</tasks>";
?>

// this is working perfectly if i have more than one record , but when it comes to a single record , the problem happens !


So, looks like you are creating XML but here is a problem if XML node has one children ActionScript will case to XML (XMLNode) if more than one to XMLList.
so how can i resolve this issue ?
Do you want to use XML?
Could It be possible that in the case of a single result you are not recieving an ArrayCollection.
If you use

ArrayCollection(getVersions.lastResult.tasks.first)

Open in new window



instead of

getVersions.lastResult.tasks.first as ArrayCollection

Open in new window


the flashplayer will fire an error. Because if you cast with "as" and the types don't match the value null is simply set. If you cast using the Constructor-like notation Cast exceptions are fired. That's why I prefer this approach much more than casting with "as".

As a side-note ... the "first" at the end of that statement would make me assume you are taking the first element of something ... sure this is the case? But if you change the cast's the problem should be easy to track down.
mokatell,
if you are getting XML why you are using ArrayCollection instead XMLListCollection?


http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/XMLListCollection.html
@dgofman .. i can unserstand what you are saying ..
but i was wondering if i have an arraycollection with one item it works

like this
<dataprovider>
<arraycollection>
<object> hello flex </object>
</arraycollection>
</dataprovider>

but when it comes from the webservice with one records it fires an error !
and if xmllistcollection is the solution , then where to use the arraycollection ?



Did you try what I suggested?
@mokatell:

if xmllistcollection is the solution , then where to use the arraycollection ?


Yes for XML data you must use XMLListCollection?


http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/XMLListCollection.html 

If data comes from List or ArrayList you should use ArrayCollection

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/ArrayCollection.html
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So, if you will not create XMLListeCollection DataGrid will do that for you anyway