Sephiroth's forums, flash, php, amf, python  

Go Back   Sephiroth's forums, flash, php, amf, python > Flash Client Side > Flex

Flex the application development solution for creating and delivering cross-platform rich Internet applications . This forum topic is about Flex IDE and Flex SDK developement questions.

Reply
 
Thread Tools Display Modes
  #1  
Old 1st June 2007, 05:14
pcMan's Avatar
pcMan pcMan is offline
Member
quite-flashed member
Points: 5,224, Level: 46 Points: 5,224, Level: 46 Points: 5,224, Level: 46
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Mexico
Posts: 63
pcMan is on a distinguished road
Unhappy ArrayCollection Error

I have tried many ways to solve the problem but i can't ... so i ask you for help today...

i have this MXML file in my project:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="ordenReporteSrv.send()">
<mx:HTTPService id="ordenReporteSrv" url="assets/orden.xml" result="ordenReporteAC = new ArrayCollection(ordenReporteSrv.lastResult.orden.reporte.tema)"/>
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;
			[Bindable]
			private var ordenReporteAC:ArrayCollection;
			private function ordenDataHandler(event:ResultEvent):void
			{
				ordenReporteAC = ordenReporteSrv.lastResult.orden.reporte.tema;	
			}
		]]>
	</mx:Script>
	<mx:DataGrid id="datagrid" dataProvider="{ordenReporteAC}" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true"/>
</mx:Application>
this is the assets/orden.xml file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<orden>
	<reporte>
		<tema id="cajon" titulo="Redondeo" inicio="1" va="1"/>
	</reporte>
	<!--<piensa>
		<tema id="tema" titulo="Estar Guars" inicio="1" va="1"/>
	</piensa>
	<mty>
		<tema id="tema" titulo="Otro titulo" inicio="1" va="1"/>
	</mty>-->
</orden>
And when i try to publish in the browser i got this Error message:
Code:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@154c3141 to Array.
	at index/__ordenReporteSrv_result()
	at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
	at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
	at mx.rpc::Responder/result()
	at mx.rpc::AsyncRequest/acknowledge()
	at ::DirectHTTPMessageResponder/completeHandler()
	at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at flash.net::URLLoader/flash.net:URLLoader::onComplete()
Any help will be well received...

thanx in advance!!
__________________
Flex - Flash - AMFPHP - MySQL
blog.navojoa.net
Reply With Quote
  #2  
Old 1st June 2007, 10:14
pcMan's Avatar
pcMan pcMan is offline
Member
quite-flashed member
Points: 5,224, Level: 46 Points: 5,224, Level: 46 Points: 5,224, Level: 46
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Mexico
Posts: 63
pcMan is on a distinguished road
i've found this error is a lil bug that can be fixed by adding more than 1 node in the parent node before passing the data to the ArrayCollection.

Thank you anyways. somebody has any good solution for this from actionscript?
__________________
Flex - Flash - AMFPHP - MySQL
blog.navojoa.net
Reply With Quote
  #3  
Old 27th June 2007, 23:25
tekati tekati is offline
Newborn member
little-flashed member
Points: 1,579, Level: 22 Points: 1,579, Level: 22 Points: 1,579, Level: 22
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Age: 41
Posts: 1
tekati is on a distinguished road
Sorry so late just joined this forum.

Sorry I am late posting this as I just joined these forums. What you refer to is a bug in my opinion but easy enough to work around. You are correct it does happen only when you return 1 result. What happens is when only 1 result is returned it is returned as an ObjectProxy instead of an Array. So just check to see if in fact you are getting a ObjectProxy or ArrayCollection and if need be use the ArrayUtil.toArray to convert it. Here is example code the work around is quite simple.

Code:
import mx.utils.ArrayUtil;

if (event.result.rows.row is ArrayCollection) {
  theArray = event.result.entries.day;
} else if (event.result.rows.row is ObjectProxy) {
   theArray = new ArrayCollection(ArrayUtil.toArray(event.result.rows.row)); 
}
Reply With Quote
  #4  
Old 14th February 2008, 07:25
anthonygreco anthonygreco is offline
Newborn member
little-flashed member
Points: 2,036, Level: 27 Points: 2,036, Level: 27 Points: 2,036, Level: 27
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2006
Age: 31
Posts: 2
anthonygreco is on a distinguished road
same here..



I'm just starting with flex. Bear with me. This is all from a tutorial I saw. I get a 1034 error type coercion failure saying it can't convert ArrayCollection to and Array.

Code:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@6bafc11 to Array.
    at index/sanDataHandler()
    at index/__sanData_result()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
    at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
    at mx.rpc::Responder/result()
    at mx.rpc::AsyncRequest/acknowledge()
    at DirectHTTPMessageResponder/completeHandler()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()
My MXML looks like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
    creationComplete="sanData.send()">
    
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            import mx.utils.ArrayUtil;
            
            [Bindable]
            private var sandwiches:ArrayCollection;
            
            private function sanDataHandler(event:ResultEvent):void
            {
                //sandwiches=new ArrayCollection(event.result.sandwichMenu.sandwich);
                sandwiches=new ArrayCollection(ArrayUtil.toArray(event.result.sandwichMenu.sandwich));
            }
            private function faultHandler(event:mx.rpc.events.FaultEvent):void
            {
                var faultInfo:String="fault description: "+event.fault.faultDetail+"\n\n";
                faultInfo+="fault faultstring: "+event.fault.faultString+"\n\n";
                mx.controls.Alert.show(faultInfo,"Fault Information");
                var eventInfo:String="event target: "+event.target+"\n\n";
                eventInfo+="event type: "+event.type+"\n\n";
                mx.controls.Alert.show(eventInfo,"Event Information");    
            }
        ]]>
    </mx:Script>
    
    <mx:HTTPService id="sanData"
        url="http://localhost/foosball/assets/sandwichData.xml"
        result="sanDataHandler(event)"
        fault="faultHandler(event)"/>
        
    <mx:DataGrid dataProvider="{sandwiches}"/>
    
    <mx:Label text="{sandwiches.getItemAt(3).name}"/>
    
</mx:Application>
And this is what my XML is:

Code:
<?xml version="1.0" encoding="utf-8"?>
<sandwichMenu>
        <sandwich>
            <name>Dagwood</name>
            <bread>Hogie</bread>
            <meat>Hot Beef</meat>
            <spread>Mayo</spread>
            <type>Cold</type>
        </sandwich>
        <sandwich>
            <name>Crooks</name>
            <bread>Whole Wheat</bread>
            <meat>Tofu Slices</meat>
            <spread>Mustard</spread>
            <type>Grilled</type>
        </sandwich>
        <sandwich>
            <name>Mountain</name>
            <bread>Sourdough</bread>
            <meat>Turkey</meat>
            <spread>Mayo</spread>
            <type>Triple Decker</type>
        </sandwich>
        <sandwich>
            <name>Pacific</name>
            <bread>Pumpernickel</bread>
            <meat>Tuna</meat>
            <spread>Mustard</spread>
            <type>Cold</type>
        </sandwich>
        <sandwich>
            <name>Shove</name>
            <bread>Rye</bread>
            <meat>Pastrami</meat>
            <spread>Thousand Island</spread>
            <type>Baked</type>
        </sandwich>
        <sandwich>
            <name>Gloucester</name>
            <bread>Whole Wheat</bread>
            <meat>Turkey</meat>
            <spread>Plain</spread>
            <type>Triple Decker</type>
        </sandwich>
</sandwichMenu>
The tutorial stated several times about using the ArrayCollection as best practices, and that that was what a dataProvider would be expecting, yet the more reading I do, it says that the dataProvider (at least for data grid) is expecting an Array. I think the purpose of using the ArrayCollection has a lot to do with the ability to use getItemAt() in bindings, and would make it rather easy to access the data. Can anyone shed some light to this? Thoughts? Ways of fixing this error?
Reply With Quote
  #5  
Old 1st June 2008, 02:08
infurio infurio is offline
Newborn member
little-flashed member
Points: 1,766, Level: 24 Points: 1,766, Level: 24 Points: 1,766, Level: 24
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Age: 24
Posts: 1
infurio is on a distinguished road
Thanks!

That little code snippet from tekati really helped... sorted my problems in one go! thanks a bunch!
Reply With Quote
  #6  
Old 31st March 2009, 14:07
dimiolra dimiolra is offline
Newborn member
little-flashed member
Points: 628, Level: 12 Points: 628, Level: 12 Points: 628, Level: 12
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2009
Posts: 1
dimiolra is on a distinguished road
Quote:
Originally Posted by infurio View Post
That little code snippet from tekati really helped... sorted my problems in one go! thanks a bunch!
Thanks Tekati for me to.
Reply With Quote
  #7  
Old 16th May 2009, 06:27
danystatic danystatic is offline
Newborn member
little-flashed member
Points: 243, Level: 4 Points: 243, Level: 4 Points: 243, Level: 4
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2009
Location: fuck it, still in the house
Posts: 1
danystatic is on a distinguished road
Yeah, I see what you mean, and it help me out a lot, I was getting there... however now I had another problem with this... and solved it, I donīt know if its a good approach, but it worked.

When instead of receiving an 2||> ArrayCollection, or an [1] ObjectProxy, I received {result.data=null} or/meaning a null result
(actually its an SQL query, received in XML format)

I had to solve it somehow... I did this:

if(evt.result.data != null)
{
if (evt.result.data.images is ArrayCollection) {
array2 = evt.result.data.images;
}
else if(evt.result.data.images is ObjectProxy) {
array2 = new ArrayCollection(ArrayUtil.toArray(evt.result.data. images));
}
}
else
{
Alert.show("Your SQL query return ZERo Results","Null Data!");
}





COULD YOU SHOW ME ANOTHER WAY??
Reply With Quote
  #8  
Old 10th June 2009, 15:21
ayanray ayanray is offline
Newborn member
little-flashed member
Points: 153, Level: 3 Points: 153, Level: 3 Points: 153, Level: 3
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Posts: 2
ayanray is on a distinguished road
don't worry about null

Update: My bad, didn't test that null case until just now. I see the issue now. Read this -> he does a good job with it: http://theruntime.com/blogs/be-sharp...XML-Nodes.aspx

Old message:

yo just wanted to say you shouldn't worry about that null data unless it's important to show that there's no data. If you convert the ObjectProxy into an Array though the ArrayUtil.toArray() your null object should be converted into an arraycollection of length = 0. thus no results should be recorded while looping through the array and it will be empty, which is equivalent to your null case.

also, get rid of the {} for the ifs and elses. Flex best practises state that if you only have 1 line of code, do if --- line of code, else -- line of code vs if {} else {}.

cheers,

ayan
www.ayanray.com

Last edited by ayanray; 10th June 2009 at 15:27. Reason: update
Reply With Quote
  #9  
Old 10th June 2009, 15:38
ayanray ayanray is offline
Newborn member
little-flashed member
Points: 153, Level: 3 Points: 153, Level: 3 Points: 153, Level: 3
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Posts: 2
ayanray is on a distinguished road
final code

thought i'd post my code to show how i do it:

var versions:ArrayCollection;
if(installersRaw[i].versions == null)
versions = new ArrayCollection();
else if(installersRaw[i].versions.version is ObjectProxy)
versions = new ArrayCollection( ArrayUtil.toArray( installersRaw[i].versions.version ) );
else if(installersRaw[i].versions.version is ArrayCollection)
versions = installersRaw[i].versions.version;
var m:int = versions.length;
for(var j:int = 0; j < m; j++)
{
trace("Version:", versions[j].version);
}
Reply With Quote
  #10  
Old 7th September 2009, 05:40
effesowly effesowly is offline
Newborn member
little-flashed member
Points: 28, Level: 1 Points: 28, Level: 1 Points: 28, Level: 1
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Sep 2009
Posts: 1
effesowly is on a distinguished road
ArrayCollection Error

Running Leopard on Intel MccBook. Get Error Code -10810 when I try to open apps. At first, only TextEdit affected, then iTunes, then other apps, finally Safari.

A Restart returned the ability to open apps, but this has been happening for a week.

Cant find what Error Code -10810 means. Does anyone know?
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:27.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Alessandro Crugnola