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="{arrayCollec tion}" .... 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 ..
i have been facing this problem since a period of time .
i have a list with ID="abc" and dataprovider="{arrayCollec
ASKER
didnt work !
can u show the code?
ASKER
as simple as it is :
<s:HTTPService id="getVersions" url="{commonMethods.URLlin k+'getVers ions.php'} " method="POST" showBusyCursor="true" result="getVersions_result Handler(ev ent)" />
protected function getVersions_resultHandler( event:Resu ltEvent):v oid
{
versionsArray = getVersions.lastResult.tas ks.first as ArrayCollection ;
OR
abc.dataprovider = getVersions.lastResult.tas ks.first as ArrayCollection
BOTH DIDN'T WORK
}
<s:List id="abc" dataProvider="{versionsArr ay}"/>
<s:HTTPService id="getVersions" url="{commonMethods.URLlin
protected function getVersions_resultHandler(
{
versionsArray = getVersions.lastResult.tas
OR
abc.dataprovider = getVersions.lastResult.tas
BOTH DIDN'T WORK
}
<s:List id="abc" dataProvider="{versionsArr
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
ASKER
<?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($r es))
{
echo "<first> <ptitle>$info[0]</ptitle> <ptype>$info[1]</ptype></f irst>";
}
echo "</tasks>";
?>
// this is working perfectly if i have more than one record , but when it comes to a single record , the problem happens !
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($r
{
echo "<first> <ptitle>$info[0]</ptitle> <ptype>$info[1]</ptype></f
}
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.
ASKER
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
instead of
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.
If you use
ArrayCollection(getVersions.lastResult.tasks.first)
instead of
getVersions.lastResult.tasks.first as ArrayCollection
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
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
ASKER
@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 ?
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, if you will not create XMLListeCollection DataGrid will do that for you anyway
To do that change your code to ID="abc" click="somefunction()";
inside that do abc.dataprovider=arrayColl