[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread valdhor
I am a little late to this party but I would have to recommend using AMF to 
pass your data back and forth. this allows you to pass objects and arrays of 
objects both ways. No need to convert objects to XML and back to objects - they 
are all just objects.

When the data comes in you can use ArrayUtil.toArray on the result and create 
an ArrayCollection from this array. An empty result will have created a zero 
length array and you can trap on that.

I use WebORB for PHP (Community Edition which is free) as the PHP middleware 
and have never had a problem. I have posted many examples on this forum of how 
to pass data back and forth. If you need any further help, I am but a post away 
;-}

I started out in my Flex learning going the XML route but soon got very 
confused, especially with trying to send arrays of data TO the server. As soon 
as I figured out how to do it with AMF I converted everything and now will not 
go back.


Best Regards



Steve



[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread James
Hi Steve. As I said earlier about using e4x I'm reluctant to use amfphp 1. 
because I already have eveything set up using regular php code and 2. I. 
struggle to find examples of how to use such methods compared to the regular 
methods of using traditional php.

Would you happen to know if it is possible to send a copy of the array 
collection that I'm receiving somehow? I basically want it so that when the 
user logs in it gets the data that we've been discussing throughout this topic 
and sets it as an array collection in flex and then sends this whole array to 
the userlinks table I have in my mysql so each user basically has a whole copy 
of the links table to themselves and can edit this by setting favourites etc. 
How would you go about this judging by the code that I've got here (the code 
that Robert provided). I'd prefer to stick to php to upload the array as this 
project is for my uni course in which I've used php throughout but I suppose I 
could use amfphp to upload the arrays?

Cheers for the advice so far.

--- In flexcoders@yahoogroups.com, valdhor valdhorli...@... wrote:

 I am a little late to this party but I would have to recommend using AMF to 
 pass your data back and forth. this allows you to pass objects and arrays of 
 objects both ways. No need to convert objects to XML and back to objects - 
 they are all just objects.
 
 When the data comes in you can use ArrayUtil.toArray on the result and create 
 an ArrayCollection from this array. An empty result will have created a zero 
 length array and you can trap on that.
 
 I use WebORB for PHP (Community Edition which is free) as the PHP middleware 
 and have never had a problem. I have posted many examples on this forum of 
 how to pass data back and forth. If you need any further help, I am but a 
 post away ;-}
 
 I started out in my Flex learning going the XML route but soon got very 
 confused, especially with trying to send arrays of data TO the server. As 
 soon as I figured out how to do it with AMF I converted everything and now 
 will not go back.
 
 
 Best Regards
 
 
 
 Steve





[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread valdhor
James

First off, I would not use AMFPHP as it is deprecated in favor of ZendAMF (Part 
of Zend Framework). I found WebORB much easier to integrate than ZendAMF.

With WebORB you use Object Oriented PHP. You create data transfer classes in 
both Flex and PHP and map them to each other. then you use class hinting in PHP 
to receive data from Flex.

You can definitely send the arraycollection to PHP. It will arrive as an array 
of objects.

One thing I think you should look into is SharedObjects in Flex. This allows 
you to save data to the local machine (Kind of like cookies but you have 100K 
of space you can use) and is very useful to hold these kinds of preferences.


Steve

--- In flexcoders@yahoogroups.com, James garymoorcroft_...@... wrote:

 Hi Steve. As I said earlier about using e4x I'm reluctant to use amfphp 1. 
 because I already have eveything set up using regular php code and 2. I. 
 struggle to find examples of how to use such methods compared to the regular 
 methods of using traditional php.
 
 Would you happen to know if it is possible to send a copy of the array 
 collection that I'm receiving somehow? I basically want it so that when the 
 user logs in it gets the data that we've been discussing throughout this 
 topic and sets it as an array collection in flex and then sends this whole 
 array to the userlinks table I have in my mysql so each user basically has a 
 whole copy of the links table to themselves and can edit this by setting 
 favourites etc. How would you go about this judging by the code that I've got 
 here (the code that Robert provided). I'd prefer to stick to php to upload 
 the array as this project is for my uni course in which I've used php 
 throughout but I suppose I could use amfphp to upload the arrays?
 
 Cheers for the advice so far.
 
 --- In flexcoders@yahoogroups.com, valdhor valdhorlists@ wrote:
 
  I am a little late to this party but I would have to recommend using AMF to 
  pass your data back and forth. this allows you to pass objects and arrays 
  of objects both ways. No need to convert objects to XML and back to objects 
  - they are all just objects.
  
  When the data comes in you can use ArrayUtil.toArray on the result and 
  create an ArrayCollection from this array. An empty result will have 
  created a zero length array and you can trap on that.
  
  I use WebORB for PHP (Community Edition which is free) as the PHP 
  middleware and have never had a problem. I have posted many examples on 
  this forum of how to pass data back and forth. If you need any further 
  help, I am but a post away ;-}
  
  I started out in my Flex learning going the XML route but soon got very 
  confused, especially with trying to send arrays of data TO the server. As 
  soon as I figured out how to do it with AMF I converted everything and now 
  will not go back.
  
  
  Best Regards
  
  
  
  Steve
 





[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread valdhor
Maybe a combination of Server based and locally saved preferences?

This is what I do. The user can set his/her own display preferences which are 
saved in SharedObjects and the data is retrieved from the server.

--- In flexcoders@yahoogroups.com, Gary Moorcroft garymoorcroft_...@... wrote:

 Actually the whole app was previously made entirely using shared objects 
 with no web based dynamic data where the user could save all of the links to 
 their local machine. The problem was of course my client wanted to add new 
 links and update the existing links as time went on which means obviously it 
 needs to all be web based.
 
 --- On Wed, 21/4/10, valdhor valdhorli...@... wrote:
 
 
 From: valdhor valdhorli...@...
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 To: flexcoders@yahoogroups.com
 Date: Wednesday, 21 April, 2010, 13:49
 
 
   
 
 
 
 James
 
 First off, I would not use AMFPHP as it is deprecated in favor of ZendAMF 
 (Part of Zend Framework). I found WebORB much easier to integrate than 
 ZendAMF.
 
 With WebORB you use Object Oriented PHP. You create data transfer classes in 
 both Flex and PHP and map them to each other. then you use class hinting in 
 PHP to receive data from Flex.
 
 You can definitely send the arraycollection to PHP. It will arrive as an 
 array of objects.
 
 One thing I think you should look into is SharedObjects in Flex. This allows 
 you to save data to the local machine (Kind of like cookies but you have 100K 
 of space you can use) and is very useful to hold these kinds of preferences.
 
 Steve
 
 --- In flexcod...@yahoogro ups.com, James garymoorcroft_ ict@ wrote:
 
  Hi Steve. As I said earlier about using e4x I'm reluctant to use amfphp 1. 
  because I already have eveything set up using regular php code and 2. I. 
  struggle to find examples of how to use such methods compared to the 
  regular methods of using traditional php.
  
  Would you happen to know if it is possible to send a copy of the array 
  collection that I'm receiving somehow? I basically want it so that when the 
  user logs in it gets the data that we've been discussing throughout this 
  topic and sets it as an array collection in flex and then sends this whole 
  array to the userlinks table I have in my mysql so each user basically has 
  a whole copy of the links table to themselves and can edit this by setting 
  favourites etc. How would you go about this judging by the code that I've 
  got here (the code that Robert provided). I'd prefer to stick to php to 
  upload the array as this project is for my uni course in which I've used 
  php throughout but I suppose I could use amfphp to upload the arrays?
  
  Cheers for the advice so far.
  
  --- In flexcod...@yahoogro ups.com, valdhor valdhorlists@  wrote:
  
   I am a little late to this party but I would have to recommend using AMF 
   to pass your data back and forth. this allows you to pass objects and 
   arrays of objects both ways. No need to convert objects to XML and back 
   to objects - they are all just objects.
   
   When the data comes in you can use ArrayUtil.toArray on the result and 
   create an ArrayCollection from this array. An empty result will have 
   created a zero length array and you can trap on that.
   
   I use WebORB for PHP (Community Edition which is free) as the PHP 
   middleware and have never had a problem. I have posted many examples on 
   this forum of how to pass data back and forth. If you need any further 
   help, I am but a post away ;-}
   
   I started out in my Flex learning going the XML route but soon got very 
   confused, especially with trying to send arrays of data TO the server. As 
   soon as I figured out how to do it with AMF I converted everything and 
   now will not go back.
   
   
   Best Regards
   
   
   
   Steve
  
 





Re: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread Gary Moorcroft
Actually the whole app was previously made entirely using shared objects with 
no web based dynamic data where the user could save all of the links to their 
local machine. The problem was of course my client wanted to add new links and 
update the existing links as time went on which means obviously it needs to all 
be web based.

--- On Wed, 21/4/10, valdhor valdhorli...@embarqmail.com wrote:


From: valdhor valdhorli...@embarqmail.com
Subject: [flexcoders] Re: Problems With my XML Created Array Collection
To: flexcoders@yahoogroups.com
Date: Wednesday, 21 April, 2010, 13:49


  



James

First off, I would not use AMFPHP as it is deprecated in favor of ZendAMF (Part 
of Zend Framework). I found WebORB much easier to integrate than ZendAMF.

With WebORB you use Object Oriented PHP. You create data transfer classes in 
both Flex and PHP and map them to each other. then you use class hinting in PHP 
to receive data from Flex.

You can definitely send the arraycollection to PHP. It will arrive as an array 
of objects.

One thing I think you should look into is SharedObjects in Flex. This allows 
you to save data to the local machine (Kind of like cookies but you have 100K 
of space you can use) and is very useful to hold these kinds of preferences.

Steve

--- In flexcod...@yahoogro ups.com, James garymoorcroft_ i...@... wrote:

 Hi Steve. As I said earlier about using e4x I'm reluctant to use amfphp 1. 
 because I already have eveything set up using regular php code and 2. I. 
 struggle to find examples of how to use such methods compared to the regular 
 methods of using traditional php.
 
 Would you happen to know if it is possible to send a copy of the array 
 collection that I'm receiving somehow? I basically want it so that when the 
 user logs in it gets the data that we've been discussing throughout this 
 topic and sets it as an array collection in flex and then sends this whole 
 array to the userlinks table I have in my mysql so each user basically has a 
 whole copy of the links table to themselves and can edit this by setting 
 favourites etc. How would you go about this judging by the code that I've got 
 here (the code that Robert provided). I'd prefer to stick to php to upload 
 the array as this project is for my uni course in which I've used php 
 throughout but I suppose I could use amfphp to upload the arrays?
 
 Cheers for the advice so far.
 
 --- In flexcod...@yahoogro ups.com, valdhor valdhorlists@  wrote:
 
  I am a little late to this party but I would have to recommend using AMF to 
  pass your data back and forth. this allows you to pass objects and arrays 
  of objects both ways. No need to convert objects to XML and back to objects 
  - they are all just objects.
  
  When the data comes in you can use ArrayUtil.toArray on the result and 
  create an ArrayCollection from this array. An empty result will have 
  created a zero length array and you can trap on that.
  
  I use WebORB for PHP (Community Edition which is free) as the PHP 
  middleware and have never had a problem. I have posted many examples on 
  this forum of how to pass data back and forth. If you need any further 
  help, I am but a post away ;-}
  
  I started out in my Flex learning going the XML route but soon got very 
  confused, especially with trying to send arrays of data TO the server. As 
  soon as I figured out how to do it with AMF I converted everything and now 
  will not go back.
  
  
  Best Regards
  
  
  
  Steve
 










  

[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread Amy


--- In flexcoders@yahoogroups.com, valdhor valdhorli...@... wrote:

 James
 
 First off, I would not use AMFPHP as it is deprecated in favor of ZendAMF 
 (Part of Zend Framework). I found WebORB much easier to integrate than 
 ZendAMF.
 
 With WebORB you use Object Oriented PHP. You create data transfer classes in 
 both Flex and PHP and map them to each other. then you use class hinting in 
 PHP to receive data from Flex.
 
 You can definitely send the arraycollection to PHP. It will arrive as an 
 array of objects.
 
 One thing I think you should look into is SharedObjects in Flex. This allows 
 you to save data to the local machine (Kind of like cookies but you have 100K 
 of space you can use) and is very useful to hold these kinds of preferences.

I would disagree that AMFPHP is deprecated... They just released a new version 
in February.

-Amy



[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread Amy


--- In flexcoders@yahoogroups.com, James garymoorcroft_...@... wrote:

 Hi Amy. Sorry I missed your post yesterday. e4x does seem good but I was just 
 a little bit worried about implementing it. As a flex beginner I tend to 
 stick to the traditional most widely used methods of doing things as a lot of 
 the times I work by looking at previous examples and applying them to my own 
 code and it's hard to find examples of things such as handling results of e4x 
 etc.

Hi, James;

If you want to do things in the traditional most widely used method, then you 
_definitely_ want to go with using e4x.  To be blunt, what Robert has told you 
to do is a newbie workaround, which could easily have been avoided by just 
using e4x.  It's unfortunate that object is the default return type for 
HTTPService, but it's very easy and quick to figure out how to fix it, 
especially if you read the FAQ's for this group.

When you have a ton of extra code to implement an unnecessary workaround, it's 
just that much more code to maintain, bloats your file size, and slows 
performance.  And, as Tracy says, in this particular instance, you also risk 
your data integrity.

If you're worried about working with e4x, I found this guide very helpful when 
I first was learning it http://dispatchevent.org/roger/as3-e4x-rundown/.

However, I'd agree with Steve that if you need to pass data both ways, you're 
probably better off using RPC remoting.  If you're interested in AMFPHP, you 
can get a fully working example here: 
http://flexdiary.blogspot.com/2009/01/lazy-loading-tree-example-file-posted.html

HTH;

Amy



[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-21 Thread valdhor
Amy

That I didn't know. AMFPHP is probably a viable option then, especially seeing 
as it is being updated.

I left AMFPHP behind once I went with WebORB and have never looked back until 
now.

--- In flexcoders@yahoogroups.com, Amy amyblankens...@... wrote:

 
 
 --- In flexcoders@yahoogroups.com, valdhor valdhorlists@ wrote:
 
  James
  
  First off, I would not use AMFPHP as it is deprecated in favor of ZendAMF 
  (Part of Zend Framework). I found WebORB much easier to integrate than 
  ZendAMF.
  
  With WebORB you use Object Oriented PHP. You create data transfer classes 
  in both Flex and PHP and map them to each other. then you use class hinting 
  in PHP to receive data from Flex.
  
  You can definitely send the arraycollection to PHP. It will arrive as an 
  array of objects.
  
  One thing I think you should look into is SharedObjects in Flex. This 
  allows you to save data to the local machine (Kind of like cookies but you 
  have 100K of space you can use) and is very useful to hold these kinds of 
  preferences.
 
 I would disagree that AMFPHP is deprecated... They just released a new 
 version in February.
 
 -Amy





RE: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-20 Thread Tracy Spratt
I know this is very late in the game, and I haven’t read the full thread, but 
this seems like a very complicated solution to the problem.  Further, the 
default resultFormat has other consequences, data type conversions for example. 
 If you have a string that looks like a number, it will get converted to a 
number, removing trailing and leading zeros and such, and sometimes this is not 
desired.  

 

Using e4x and looping over the categories.category XMLList is very simple. 
XMLLists are never null, but empty nodes just result in a zero length, which is 
easy to test for.

 

Tracy Spratt

 

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of James
Sent: Monday, April 19, 2010 3:39 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Problems With my XML Created Array Collection

 

  

I've noticed that if I remove all items from the mysql table which populates 
the remote xml file the xml that is produced is simply this:-

?xml version=1.0 ? 
categories / 

i.e. all of the nodes are removed so this means my app is looking for nodes 
that aren't actually there so it seems I need another else if bracket to deal 
with this but I haven't got a clue for how to check if an xml file is empty or 
null or whatever you'd call the above in flex and what to do within this else 
if bracket if it's not.

--- In flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com, 
Robert Moss rdm0...@... wrote:

 In essence yes, I do not think I would do it as part of the button click, but 
 instead clear it before the IF in the result handler with LinksFullAC.source 
 = new Array(); or LinksFullAC.removeAll(); I prefer the former. 
 
 As for your error, I'm not sure what's happening, but you should be able to 
 set a break in the result handler and see what is getting returned. It looks 
 like for the combination you describe, categories is not getting returned for 
 some reason. You'll need to figure out why and trap for it. The same goes for 
 returning 0 records. See what is getting returned and trap for it.
 
 
 
 
 
 
 From: James garymoorcroft_...@...
 To: flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com
 Sent: Mon, April 19, 2010 12:47:15 PM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
 
 Hi Robert. Thanks so much for that my friend. 
 
 I have some problems with it though. You see I have an event in my app 
 applied to a button (refresh button) which resends data via the LinksService 
 i.e. LinksService. send and I've noticed that with your code if there is only 
 1 link i.e. 1 node and I click the refresh button it seems to keep recreating 
 that 1 over and over again as if it's recreating the same object in the array 
 collection or something. This doesn't happen if their are 2 or more 
 links/nodes/ objects. Perhaps I'll have to get the refresh button to empty 
 the array collection first before sending the data i.e. it's click function 
 would be LinksFullAC. flush; LinksService. send() Am I right?
 
 I've also noticed now with your code applied if I select an item in the 
 tilelist and click the reresh button I get the error Property categories not 
 found on String and there is no default value which is indicating the error 
 at the if statement in the code you gave me and the LinksService itself. Any 
 idea what's causing this?
 
 Another question though what if the xml contains no nodes? 
 
 You see my xml file is dynamic, I have a variable in my app called categoryid 
 and that variable is based on a category that the user selects in my app and 
 is submitted to getlinks.php which gets all the records from my mysql table 
 which contain that specific submitted categoryid and output them as the xml 
 file. Some categoryids have no records (the user can add and delte records 
 via my app). Is there any way of getting it to handle 0 records/nodes as well 
 as handling muliple records/1record which it seems to already do?
 
 Thanks so much for your help. Sorry to be a pain :-(
 
 --- In flexcod...@yahoogro ups.com, Robert Moss rdm0004@  wrote:
 
  This is not exactly how I would implement, but you should get the idea. If 
  you have multiple category nodes, then your LinksService. lastResult. 
  categories. category is returned as an ArrayCollection and your code works. 
  If it only has one node then LinksService. lastResult. categories. category 
  is returned as an ObjectProxy. So in your return method you could have the 
  following.
  
  if(LinksService. lastResult. categories. category is ArrayCollection) {
  LinksFullAC= LinksService. lastResult. categories. category as 
  ArrayCollection;
  }else
  {
  var oCat:Object = new Object();
  oCat.id = LinksService. lastResult. categories. category. id;
  oCat.label = LinksService. lastResult. categories. category. label;
  oCat.icon = LinksService. lastResult. categories. category. icon;
  LinksFullAC. addItem(oCat) ; // NOTE

RE: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-20 Thread Tracy Spratt
Here is some untested code to loop (you will need to correct the automatic 
capitalization ): It is also more verbose than necessary, just for clarity.

 

Var xmlResult:XML = event.result as XML;

Trace(xmlResult.toXMLString()); //to verify your xml

Var xlResult:XMLList = xmlResult.category;

Var acResult:ArrayCollection = new ArrayCollection();

Var xmlCategory:XML;

For (var i:uint=0;ixlResult.length()) { //watch out for the length() method, 
not property

  xmlCategory = xlResult[i]; 

  
acResult.addItem({id:xmlCategory.id.text(),label:xmlCategory.label.text(),icon:xmlCategory.icon.text()});
  //usually the text) can be omitted, but I use it by habit.

}

myTileList.dataProvider = acResult;

 

And DO avoid using lastResult in functions.  It is intended for binding 
espressions.

 

Tracy Spratt,

Lariat Services, development services available

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Tracy Spratt
Sent: Tuesday, April 20, 2010 12:39 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: Problems With my XML Created Array Collection

 

  

I know this is very late in the game, and I haven’t read the full thread, but 
this seems like a very complicated solution to the problem.  Further, the 
default resultFormat has other consequences, data type conversions for example. 
 If you have a string that looks like a number, it will get converted to a 
number, removing trailing and leading zeros and such, and sometimes this is not 
desired.  

 

Using e4x and looping over the categories.category XMLList is very simple. 
XMLLists are never null, but empty nodes just result in a zero length, which is 
easy to test for.

 

Tracy Spratt

 

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of James
Sent: Monday, April 19, 2010 3:39 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Problems With my XML Created Array Collection

 

  

I've noticed that if I remove all items from the mysql table which populates 
the remote xml file the xml that is produced is simply this:-

?xml version=1.0 ? 
categories / 

i.e. all of the nodes are removed so this means my app is looking for nodes 
that aren't actually there so it seems I need another else if bracket to deal 
with this but I haven't got a clue for how to check if an xml file is empty or 
null or whatever you'd call the above in flex and what to do within this else 
if bracket if it's not.

--- In flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com, 
Robert Moss rdm0...@... wrote:

 In essence yes, I do not think I would do it as part of the button click, but 
 instead clear it before the IF in the result handler with LinksFullAC.source 
 = new Array(); or LinksFullAC.removeAll(); I prefer the former. 
 
 As for your error, I'm not sure what's happening, but you should be able to 
 set a break in the result handler and see what is getting returned. It looks 
 like for the combination you describe, categories is not getting returned for 
 some reason. You'll need to figure out why and trap for it. The same goes for 
 returning 0 records. See what is getting returned and trap for it.
 
 
 
 
 
 
 From: James garymoorcroft_...@...
 To: flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com
 Sent: Mon, April 19, 2010 12:47:15 PM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
 
 Hi Robert. Thanks so much for that my friend. 
 
 I have some problems with it though. You see I have an event in my app 
 applied to a button (refresh button) which resends data via the LinksService 
 i.e. LinksService. send and I've noticed that with your code if there is only 
 1 link i.e. 1 node and I click the refresh button it seems to keep recreating 
 that 1 over and over again as if it's recreating the same object in the array 
 collection or something. This doesn't happen if their are 2 or more 
 links/nodes/ objects. Perhaps I'll have to get the refresh button to empty 
 the array collection first before sending the data i.e. it's click function 
 would be LinksFullAC. flush; LinksService. send() Am I right?
 
 I've also noticed now with your code applied if I select an item in the 
 tilelist and click the reresh button I get the error Property categories not 
 found on String and there is no default value which is indicating the error 
 at the if statement in the code you gave me and the LinksService itself. Any 
 idea what's causing this?
 
 Another question though what if the xml contains no nodes? 
 
 You see my xml file is dynamic, I have a variable in my app called categoryid 
 and that variable is based on a category that the user selects in my app and 
 is submitted to getlinks.php which gets all the records from my mysql table 
 which contain that specific submitted categoryid and output them as the xml 
 file. Some categoryids have no records (the user can add and delte records

[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-20 Thread Amy


--- In flexcoders@yahoogroups.com, Robert Moss rdm0...@... wrote:

 Yes use a third if statement like:  if(event.result.categories)   
 if(event.result.categories != null) should also work
 
 Notice I used event.result instead of LinksService.lastResult.  Small change, 
 but you should get in the habit as LinksService.lastResult will cause some 
 pain in the future if you decide to change it's name for some reason.  
 
 Amy suggested using e4x which is probably the correct answer as e4x grants 
 you consistency ( you do not have the arrayCollection returned sometimes and 
 ObjectProxy others) and allows you to work with XML in actionscript like XML 
 was meant to be accessed.  You will still have to trap for the same issues, 
 just implemented in a different way.   We do not always use e4x although we 
 probably should, being lazy will probably bite us one of these days.

I think you've misunderstood.  By changing the result format from the default 
of object to e4x, you _avoid_ the problem the OP had, which is if there is only 
one object returned, you get a different result than if you have multiple 
objects returned.  You don't have to trap for the problem, because it goes 
away.  If there is only one node, you get one node.  If there are multiple 
nodes, you get multiple nodes.

But whatever.

-Amy



[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-20 Thread James
Thanks Tracy that looks good. I may try something similar in the future. I've 
managed to get the previous example provided by robert working though so 
basically I'm thinking if it isn't broke don't fix it. :-) It's all that I 
require really as I'm only using it to display the results and it covers 
everything I need. Thanks a lot for your advice.

While you're hear would you happen to know how to upload an entire array 
collection to a server via php/http request? You see the thing is at the moment 
I have an app which allows users to create links and remove links which 
directly creates/removes them in the mysql database I have which holds my data.

To explain what I want basically I have a links table which contains all the 
available links and a userlinks table in my mysql database. When the user 
creates a new account via my app all the links from the links table are 
displayed in the app using the method we've been discussing but now I want the 
user to be able to add the entire contents of this to the userlinks table. The 
purpose of this is the user can favorite each link which will alter a boolean 
field in the userlinks table which will mean in turn when a user logs in with 
an existing account the links they've favourited will be displayed.

So basically firstly I need to know how to add/send mulitple records via 
flex/php. I have no problem adding/removing and updating individual records but 
I now need to know how to add multiple ones at once. Is there any way of doing 
this and do you know of any similar examples?

--- In flexcoders@yahoogroups.com, Tracy Spratt tr...@... wrote:

 Here is some untested code to loop (you will need to correct the automatic 
 capitalization ): It is also more verbose than necessary, just for clarity.
 
  
 
 Var xmlResult:XML = event.result as XML;
 
 Trace(xmlResult.toXMLString()); //to verify your xml
 
 Var xlResult:XMLList = xmlResult.category;
 
 Var acResult:ArrayCollection = new ArrayCollection();
 
 Var xmlCategory:XML;
 
 For (var i:uint=0;ixlResult.length()) { //watch out for the length() method, 
 not property
 
   xmlCategory = xlResult[i]; 
 
   
 acResult.addItem({id:xmlCategory.id.text(),label:xmlCategory.label.text(),icon:xmlCategory.icon.text()});
   //usually the text) can be omitted, but I use it by habit.
 
 }
 
 myTileList.dataProvider = acResult;
 
  
 
 And DO avoid using lastResult in functions.  It is intended for binding 
 espressions.
 
  
 
 Tracy Spratt,
 
 Lariat Services, development services available
 
   _  
 
 From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On 
 Behalf Of Tracy Spratt
 Sent: Tuesday, April 20, 2010 12:39 PM
 To: flexcoders@yahoogroups.com
 Subject: RE: [flexcoders] Re: Problems With my XML Created Array Collection
 
  
 
   
 
 I know this is very late in the game, and I haven’t read the full thread, 
 but this seems like a very complicated solution to the problem.  Further, the 
 default resultFormat has other consequences, data type conversions for 
 example.  If you have a string that looks like a number, it will get 
 converted to a number, removing trailing and leading zeros and such, and 
 sometimes this is not desired.  
 
  
 
 Using e4x and looping over the categories.category XMLList is very simple. 
 XMLLists are never null, but empty nodes just result in a zero length, which 
 is easy to test for.
 
  
 
 Tracy Spratt
 
  
 
   _  
 
 From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On 
 Behalf Of James
 Sent: Monday, April 19, 2010 3:39 PM
 To: flexcoders@yahoogroups.com
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
  
 
   
 
 I've noticed that if I remove all items from the mysql table which populates 
 the remote xml file the xml that is produced is simply this:-
 
 ?xml version=1.0 ? 
 categories / 
 
 i.e. all of the nodes are removed so this means my app is looking for nodes 
 that aren't actually there so it seems I need another else if bracket to deal 
 with this but I haven't got a clue for how to check if an xml file is empty 
 or null or whatever you'd call the above in flex and what to do within this 
 else if bracket if it's not.
 
 --- In flexcod...@yahoogro mailto:flexcoders%40yahoogroups.com ups.com, 
 Robert Moss rdm0004@ wrote:
 
  In essence yes, I do not think I would do it as part of the button click, 
  but instead clear it before the IF in the result handler with 
  LinksFullAC.source = new Array(); or LinksFullAC.removeAll(); I prefer the 
  former. 
  
  As for your error, I'm not sure what's happening, but you should be able to 
  set a break in the result handler and see what is getting returned. It 
  looks like for the combination you describe, categories is not getting 
  returned for some reason. You'll need to figure out why and trap for it. 
  The same goes for returning 0 records. See what is getting returned and 
  trap

[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-20 Thread James
Hi Amy. Sorry I missed your post yesterday. e4x does seem good but I was just a 
little bit worried about implementing it. As a flex beginner I tend to stick to 
the traditional most widely used methods of doing things as a lot of the times 
I work by looking at previous examples and applying them to my own code and 
it's hard to find examples of things such as handling results of e4x etc.

Cheers.

--- In flexcoders@yahoogroups.com, Amy amyblankens...@... wrote:

 
 
 --- In flexcoders@yahoogroups.com, Robert Moss rdm0004@ wrote:
 
  Yes use a third if statement like:  if(event.result.categories)   
  if(event.result.categories != null) should also work
  
  Notice I used event.result instead of LinksService.lastResult.  Small 
  change, but you should get in the habit as LinksService.lastResult will 
  cause some pain in the future if you decide to change it's name for some 
  reason.  
  
  Amy suggested using e4x which is probably the correct answer as e4x grants 
  you consistency ( you do not have the arrayCollection returned sometimes 
  and ObjectProxy others) and allows you to work with XML in actionscript 
  like XML was meant to be accessed.  You will still have to trap for the 
  same issues, just implemented in a different way.   We do not always use 
  e4x although we probably should, being lazy will probably bite us one of 
  these days.
 
 I think you've misunderstood.  By changing the result format from the default 
 of object to e4x, you _avoid_ the problem the OP had, which is if there is 
 only one object returned, you get a different result than if you have 
 multiple objects returned.  You don't have to trap for the problem, because 
 it goes away.  If there is only one node, you get one node.  If there are 
 multiple nodes, you get multiple nodes.
 
 But whatever.
 
 -Amy





[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-20 Thread sminrana



return the xml as a string from PHP file and cast that return string 
in flex like this var xml:XML = XML(data.result);
then do whatever it needs like XMLList and XMLListCollection;

then is the resultEvent you can check like this

if (data.result != )
{
xml:XML = XML(data.result);
}
else
{
Alert.show(something);
}






--- In flexcoders@yahoogroups.com, James garymoorcroft_...@... wrote:

 In my app I have an array collection which populates a tilelist. This array 
 collection is populated by a remote xml file via a http request. Problem is 
 if the xml only has 1 or no nodes I get a null object reference error. I know 
 this is a known problem but I've never been able to find a valid solution for 
 it which could be applied to my code. I've heard of looping through the xml 
 to create an array collection or using xmllist collection but I don't know 
 how these can be done whilst still allowing the data to be displayed in the 
 tilelist. Can anyone help me out please?
 
 The code for my httpservice, array collcection I'm trying to make and the 
 result of the http service and the tilelist it populates is shown below. As I 
 say this all works fine as long as the xml has more than 1 node but causes 
 the error if it doesn't:-
 
 mx:HTTPService id=LinksService result=linksResultHandler(event) 
 resultFormat=object method=POST 
 url=http://www.coolvisiontest.com/getlinks.php/
 
 mx:Script
   ![CDATA[
   
   import mx.rpc.events.ResultEvent;
   import mx.collections.ArrayCollection;
 
   [Bindable] private var LinksFullAC:ArrayCollection;
   
   private function linksResultHandler(event:ResultEvent):void
   {
   LinksFullAC=LinksService.lastResult.categories.category 
 as ArrayCollection;
   }
   
 
   ]]
 /mx:Script
 
 mx:TileList id=linkChoice  dataProvider={LinksFullAC} height=365 
 width=665/
 
 Here's my xml structure:-
 
 categories
  category
   id/id 
   label/label 
   icon/icon 
  /category
 /categories
 
 Obviously I need the array collection to be populated by id, label and icon.
 
 Thanks for any suggestions.





[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread James
The thing is my xml is retrieved from a mysql database table which sometimes 
will have no records or 1 record which will mean the xml will have only 1 or no 
nodes which in turn causes the problem whereas sometimes it has many records 
therefore the xml file would have many nodes which would mean no problems.

I've heard of looping but can't figure out how to do it or apply it to my code. 
I've tried simply changing the array collection to xmllist collection but then 
the data doesn't seem to appear in my tilelist.

How would you loop using my specific code there because I always need it 
returned as an array collection to populate the tilelist but have no idea how 
to loop?

Cheers for your help so far.

--- In flexcoders@yahoogroups.com, Robert Moss rdm0...@... wrote:

 We had the same issue, and in our case it was an easy fix.  When we read in 
 the XML it was returning as an ArrayCollection as long as there were multiple 
 nodes.  As you have found, if it was only one node it returned as a generic 
 object not an ArrayCollection.  We were already looping through the 
 ArrayCollection to populate value objects that we were using to populate our 
 list.  So before the loop we added, if xmlObject is an ArrayCollection than 
 loop else populate VO with returned data.  Worked without issues ever since.
 
 Robert
 
 
 
 
 
 
 From: thomas parquier mailingli...@...
 To: flexcoders@yahoogroups.com
 Sent: Mon, April 19, 2010 9:27:13 AM
 Subject: Re: [flexcoders] Problems With my XML Created Array Collection
 
   
 what about xmllistcollection ?;
 
 ---
 thomas parquier
 http://www.web- attitude. fr/realisations/
 msn : thomas.parquier@ web-attitude. fr
 softphone : sip:webattitude@ ekiga.net
 téléphone portable : +33601 822 056
 
 
 
 2010/4/19 James garymoorcroft_ i...@yahoo. co.uk
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   
 
 
  
   
  
 In my app I have an array collection which populates a tilelist. This array 
 collection is populated by a remote xml file via a http request. Problem is 
 if the xml only has 1 or no nodes I get a null object reference error. I 
 know this is a known problem but I've never been able to find a valid 
 solution for it which could be applied to my code. I've heard of looping 
 through the xml to create an array collection or using xmllist collection 
 but I don't know how these can be done whilst still allowing the data to be 
 displayed in the tilelist. Can anyone help me out please?
 
 The code for my httpservice, array collcection I'm trying to make and the 
 result of the http service and the tilelist it populates is shown below. As 
 I say this all works fine as long as the xml has more than 1 node but 
 causes the error if it doesn't:-
 
 mx:HTTPService id=LinksService result=linksResultHandler( event) 
 resultFormat=object method=POST url=http://www.coolvisi ontest.com/ 
 getlinks. php/
 
 mx:Script
 ![CDATA[
 
 import mx.rpc.events. ResultEvent;
 import mx.collections. ArrayCollection;
 
 [Bindable] private var LinksFullAC: ArrayCollection;
 
 private function linksResultHandler( event:ResultEven t):void
 {
 LinksFullAC= LinksService. lastResult. categories. 
  category as ArrayCollection;
 }
 
 
 ]]
 /mx:Script
 
 mx:TileList id=linkChoice  dataProvider={LinksFullAC} height=365 
 width=665/
 
 Here's my xml structure:-
 
 categories
  category
   id/id 
   label/label 
   icon/icon 
  /category
 /categories
 
 Obviously I need the array collection to be populated by id, label and icon.
 
 Thanks for any suggestions.
 
 





Re: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread Robert Moss
This is not exactly how I would implement, but you should get the idea.  If you 
have multiple category nodes, then your 
LinksService.lastResult.categories.category is returned as an ArrayCollection 
and your code works.  If it only has one node then 
LinksService.lastResult.categories.category is returned as an ObjectProxy.  So 
in your return method you could have the following.

if(LinksService.lastResult.categories.category is ArrayCollection){
 LinksFullAC=LinksService.lastResult.categories.category as 
ArrayCollection;
 }else
 {
 var oCat:Object = new Object();
 oCat.id = LinksService.lastResult.categories.category.id;
 oCat.label = LinksService.lastResult.categories.category.label;
 oCat.icon = LinksService.lastResult.categories.category.icon;
 LinksFullAC.addItem(oCat);  // NOTE: LinksFullAC needs to not only be 
previously declared, but must also me instantiated with new ArrayCollection() 
for this line to work.
 
 }






From: James garymoorcroft_...@yahoo.co.uk
To: flexcoders@yahoogroups.com
Sent: Mon, April 19, 2010 9:58:33 AM
Subject: [flexcoders] Re: Problems With my XML Created Array Collection

  
The thing is my xml is retrieved from a mysql database table which sometimes 
will have no records or 1 record which will mean the xml will have only 1 or no 
nodes which in turn causes the problem whereas sometimes it has many records 
therefore the xml file would have many nodes which would mean no problems.

I've heard of looping but can't figure out how to do it or apply it to my code. 
I've tried simply changing the array collection to xmllist collection but then 
the data doesn't seem to appear in my tilelist.

How would you loop using my specific code there because I always need it 
returned as an array collection to populate the tilelist but have no idea how 
to loop?

Cheers for your help so far.

--- In flexcod...@yahoogro ups.com, Robert Moss rdm0...@...  wrote:

 We had the same issue, and in our case it was an easy fix.  When we read in 
 the XML it was returning as an ArrayCollection as long as there were multiple 
 nodes.  As you have found, if it was only one node it returned as a generic 
 object not an ArrayCollection.  We were already looping through the 
 ArrayCollection to populate value objects that we were using to populate our 
 list.  So before the loop we added, if xmlObject is an ArrayCollection than 
 loop else populate VO with returned data.  Worked without issues ever since.
 
 Robert
 
 
 
 
 
  _ _ __
 From: thomas parquier mailinglists@ ...
 To: flexcod...@yahoogro ups.com
 Sent: Mon, April 19, 2010 9:27:13 AM
 Subject: Re: [flexcoders] Problems With my XML Created Array Collection
 
 
 what about xmllistcollection ?;
 
 ---
 thomas parquier
 http://www.web- attitude. fr/realisations/
 msn : thomas.parquier@ web-attitude. fr
 softphone : sip:webattitude@ ekiga.net
 téléphone portable : +33601 822 056
 
 
 
 2010/4/19 James garymoorcroft_ i...@yahoo. co.uk
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   
 
 
  
  
  
 In my app I have an array collection which populates a tilelist. This array 
 collection is populated by a remote xml file via a http request. Problem is 
 if the xml only has 1 or no nodes I get a null object reference error. I 
 know this is a known problem but I've never been able to find a valid 
 solution for it which could be applied to my code. I've heard of looping 
 through the xml to create an array collection or using xmllist collection 
 but I don't know how these can be done whilst still allowing the data to be 
 displayed in the tilelist. Can anyone help me out please?
 
 The code for my httpservice, array collcection I'm trying to make and the 
 result of the http service and the tilelist it populates is shown below. As 
 I say this all works fine as long as the xml has more than 1 node but 
 causes the error if it doesn't:-
 
 http://www.coolvisi ontest.com/ getlinks. php/
 
 mx:Script
 ![CDATA[
 
 import mx.rpc.events. ResultEvent;
 import mx.collections. ArrayCollection;
 
 [Bindable] private var LinksFullAC: ArrayCollection;
 
 private function linksResultHandler( event:ResultEven t):void
 {
 LinksFullAC= LinksService. lastResult. categories. 
  category as ArrayCollection;
 }
 
 
 ]]
 /mx:Script
 
 mx:TileList id=linkChoice  dataProvider= {LinksFullAC}  height=365 
 width=665/ 
 
 Here's my xml structure:-
 
 categories
  category
   id/id 
   label/label 
   icon/icon 
  /category
 /categories
 
 Obviously I need the array collection to be populated by id, label and icon.
 
 Thanks for any suggestions.
 
 



 


  

[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread James
Hi Robert. Thanks so much for that my friend. 

I have some problems with it though. You see I have an event in my app applied 
to a button (refresh button) which resends data via the LinksService i.e. 
LinksService.send and I've noticed that with your code if there is only 1 link 
i.e. 1 node and I click the refresh button it seems to keep recreating that 1 
over and over again as if it's recreating the same object in the array 
collection or something. This doesn't happen if their are 2 or more 
links/nodes/objects. Perhaps I'll have to get the refresh button to empty the 
array collection first before sending the data i.e. it's click function would 
be LinksFullAC.flush; LinksService.send() Am I right?

I've also noticed now with your code applied if I select an item in the 
tilelist and click the reresh button I get the error Property categories not 
found on String and there is no default value which is indicating the error at 
the if statement in the code you gave me and the LinksService itself. Any idea 
what's causing this?

Another question though what if the xml contains no nodes? 

You see my xml file is dynamic, I have a variable in my app called categoryid 
and that variable is based on a category that the user selects in my app and is 
submitted to getlinks.php which gets all the records from my mysql table which 
contain that specific submitted categoryid and output them as the xml file. 
Some categoryids have no records (the user can add and delte records via my 
app). Is there any way of getting it to handle 0 records/nodes as well as 
handling muliple records/1record which it seems to already do?

Thanks so much for your help. Sorry to be a pain :-(

--- In flexcoders@yahoogroups.com, Robert Moss rdm0...@... wrote:

 This is not exactly how I would implement, but you should get the idea.  If 
 you have multiple category nodes, then your 
 LinksService.lastResult.categories.category is returned as an ArrayCollection 
 and your code works.  If it only has one node then 
 LinksService.lastResult.categories.category is returned as an ObjectProxy.  
 So in your return method you could have the following.
 
 if(LinksService.lastResult.categories.category is ArrayCollection){
  LinksFullAC=LinksService.lastResult.categories.category as 
 ArrayCollection;
  }else
  {
  var oCat:Object = new Object();
  oCat.id = LinksService.lastResult.categories.category.id;
  oCat.label = LinksService.lastResult.categories.category.label;
  oCat.icon = LinksService.lastResult.categories.category.icon;
  LinksFullAC.addItem(oCat);  // NOTE: LinksFullAC needs to not only 
 be previously declared, but must also me instantiated with new 
 ArrayCollection() for this line to work.
  
  }
 
 
 
 
 
 
 From: James garymoorcroft_...@...
 To: flexcoders@yahoogroups.com
 Sent: Mon, April 19, 2010 9:58:33 AM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
   
 The thing is my xml is retrieved from a mysql database table which sometimes 
 will have no records or 1 record which will mean the xml will have only 1 or 
 no nodes which in turn causes the problem whereas sometimes it has many 
 records therefore the xml file would have many nodes which would mean no 
 problems.
 
 I've heard of looping but can't figure out how to do it or apply it to my 
 code. I've tried simply changing the array collection to xmllist collection 
 but then the data doesn't seem to appear in my tilelist.
 
 How would you loop using my specific code there because I always need it 
 returned as an array collection to populate the tilelist but have no idea how 
 to loop?
 
 Cheers for your help so far.
 
 --- In flexcod...@yahoogro ups.com, Robert Moss rdm0004@  wrote:
 
  We had the same issue, and in our case it was an easy fix.  When we read in 
  the XML it was returning as an ArrayCollection as long as there were 
  multiple nodes.  As you have found, if it was only one node it returned as 
  a generic object not an ArrayCollection.  We were already looping through 
  the ArrayCollection to populate value objects that we were using to 
  populate our list.  So before the loop we added, if xmlObject is an 
  ArrayCollection than loop else populate VO with returned data.  Worked 
  without issues ever since.
  
  Robert
  
  
  
  
  
   _ _ __
  From: thomas parquier mailinglists@ ...
  To: flexcod...@yahoogro ups.com
  Sent: Mon, April 19, 2010 9:27:13 AM
  Subject: Re: [flexcoders] Problems With my XML Created Array Collection
  
  
  what about xmllistcollection ?;
  
  ---
  thomas parquier
  http://www.web- attitude. fr/realisations/
  msn : thomas.parquier@ web-attitude. fr
  softphone : sip:webattitude@ ekiga.net
  téléphone portable : +33601 822 056
  
  
  
  2010/4/19 James garymoorcroft_ i...@yahoo. co.uk

Re: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread Robert Moss
In essence yes, I do not think I would do it as part of the button click, but 
instead clear it before the IF in the result handler with LinksFullAC.source = 
new Array();  or LinksFullAC.removeAll();  I prefer the former.  

As for your error, I'm not sure what's happening, but you should be able to set 
a break in the result handler and see what is getting returned.  It looks like 
for the combination you describe, categories is not getting returned for some 
reason.  You'll need to figure out why and trap for it.  The same goes for 
returning 0 records.  See what is getting returned and trap for it.






From: James garymoorcroft_...@yahoo.co.uk
To: flexcoders@yahoogroups.com
Sent: Mon, April 19, 2010 12:47:15 PM
Subject: [flexcoders] Re: Problems With my XML Created Array Collection

  
Hi Robert. Thanks so much for that my friend. 

I have some problems with it though. You see I have an event in my app applied 
to a button (refresh button) which resends data via the LinksService i.e. 
LinksService. send and I've noticed that with your code if there is only 1 link 
i.e. 1 node and I click the refresh button it seems to keep recreating that 1 
over and over again as if it's recreating the same object in the array 
collection or something. This doesn't happen if their are 2 or more 
links/nodes/ objects. Perhaps I'll have to get the refresh button to empty the 
array collection first before sending the data i.e. it's click function would 
be LinksFullAC. flush; LinksService. send() Am I right?

I've also noticed now with your code applied if I select an item in the 
tilelist and click the reresh button I get the error Property categories not 
found on String and there is no default value which is indicating the error at 
the if statement in the code you gave me and the LinksService itself. Any idea 
what's causing this?

Another question though what if the xml contains no nodes? 

You see my xml file is dynamic, I have a variable in my app called categoryid 
and that variable is based on a category that the user selects in my app and is 
submitted to getlinks.php which gets all the records from my mysql table which 
contain that specific submitted categoryid and output them as the xml file. 
Some categoryids have no records (the user can add and delte records via my 
app). Is there any way of getting it to handle 0 records/nodes as well as 
handling muliple records/1record which it seems to already do?

Thanks so much for your help. Sorry to be a pain :-(

--- In flexcod...@yahoogro ups.com, Robert Moss rdm0...@...  wrote:

 This is not exactly how I would implement, but you should get the idea.  If 
 you have multiple category nodes, then your LinksService. lastResult. 
 categories. category is returned as an ArrayCollection and your code works.  
 If it only has one node then LinksService. lastResult. categories. category 
 is returned as an ObjectProxy.  So in your return method you could have the 
 following.
 
 if(LinksService. lastResult. categories. category is ArrayCollection) {
  LinksFullAC= LinksService. lastResult. categories. category as 
 ArrayCollection;
  }else
  {
  var oCat:Object = new Object();
 oCat.id = LinksService. lastResult. categories. category. id;
  oCat.label = LinksService. lastResult. categories. category. label;
  oCat.icon = LinksService. lastResult. categories. category. icon;
  LinksFullAC. addItem(oCat) ;  // NOTE: LinksFullAC needs to not only 
 be previously declared, but must also me instantiated with new 
 ArrayCollection( ) for this line to work.
 
  }
 
 
 
 
 
  _ _ __
 From: James garymoorcroft_ i...@...
 To: flexcod...@yahoogro ups.com
 Sent: Mon, April 19, 2010 9:58:33 AM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
 
 The thing is my xml is retrieved from a mysql database table which sometimes 
 will have no records or 1 record which will mean the xml will have only 1 or 
 no nodes which in turn causes the problem whereas sometimes it has many 
 records therefore the xml file would have many nodes which would mean no 
 problems.
 
 I've heard of looping but can't figure out how to do it or apply it to my 
 code. I've tried simply changing the array collection to xmllist collection 
 but then the data doesn't seem to appear in my tilelist.
 
 How would you loop using my specific code there because I always need it 
 returned as an array collection to populate the tilelist but have no idea how 
 to loop?
 
 Cheers for your help so far.
 
 --- In flexcod...@yahoogro ups.com, Robert Moss rdm0004@  wrote:
 
  We had the same issue, and in our case it was an easy fix.  When we read in 
  the XML it was returning as an ArrayCollection as long as there were 
  multiple nodes.  As you have found, if it was only one node it returned as 
  a generic object not an ArrayCollection.  We were already looping through

[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread Amy


--- In flexcoders@yahoogroups.com, James garymoorcroft_...@... wrote:

 The thing is my xml is retrieved from a mysql database table which sometimes 
 will have no records or 1 record which will mean the xml will have only 1 or 
 no nodes which in turn causes the problem whereas sometimes it has many 
 records therefore the xml file would have many nodes which would mean no 
 problems.
 
 I've heard of looping but can't figure out how to do it or apply it to my 
 code. I've tried simply changing the array collection to xmllist collection 
 but then the data doesn't seem to appear in my tilelist.
 
 How would you loop using my specific code there because I always need it 
 returned as an array collection to populate the tilelist but have no idea how 
 to loop?

Try setting the result format to e4x.  Probably no one stepped forward to 
answer this because it is covered in the FAQ ;-).



[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread James
You were right about removeall (flush ha whoops) helping. I applied removeall 
before the if statements like you said and the first error is now gone.

The only problem I have now is the error which occurs when there are NO nodes 
in the xml i.e. all items have been removed and there are no values in my mysql 
table which relate to that specific category id.

I've changed the code to this:-

private function linksResultHandler(event:ResultEvent):void
{
LinksFullAC.removeAll();
if(LinksService.lastResult.categories.category is ArrayCollection) {
LinksFullAC=LinksService.lastResult.categories.category as 
ArrayCollection;
}else if (LinksService.lastResult.categories.category is ObjectProxy)
{
var oCat:Object = new Object();
oCat.linkid = 
LinksService.lastResult.categories.category.linkid;
oCat.categoryid = 
LinksService.lastResult.categories.category.categoryid;   
oCat.label = LinksService.lastResult.categories.category.label;
oCat.icon = LinksService.lastResult.categories.category.icon;
oCat.link = LinksService.lastResult.categories.category.link;
LinksFullAC.addItem(oCat);
}
}

The thing is though in that code I have the first if statement to check for if 
the result is an array collection which sets it as an array collection, the 
second if statement which if it is an object proxy adds the single object to 
the array collection but I think what I'll need is a third if statement which 
checks if the xml is empty/null or something and assign what will happen if it 
is null. Do you know of any way to do this and if so what do you think is best 
to set as the operation of such an if statement to make sure this error doesn't 
occur anymore? I thought it might be something like:-

if(LinksService.lastResult.categories.category is null)

but there seems to be no such thing. Any ideas?

Sorry to keep hassling but it's pretty much the last hiccup I've got in my app 
and I always try to pick the brains of guys who know their stuff as much as I 
can :-)

--- In flexcoders@yahoogroups.com, Robert Moss rdm0...@... wrote:

 In essence yes, I do not think I would do it as part of the button click, but 
 instead clear it before the IF in the result handler with LinksFullAC.source 
 = new Array();  or LinksFullAC.removeAll();  I prefer the former.  
 
 As for your error, I'm not sure what's happening, but you should be able to 
 set a break in the result handler and see what is getting returned.  It looks 
 like for the combination you describe, categories is not getting returned for 
 some reason.  You'll need to figure out why and trap for it.  The same goes 
 for returning 0 records.  See what is getting returned and trap for it.
 
 
 
 
 
 
 From: James garymoorcroft_...@...
 To: flexcoders@yahoogroups.com
 Sent: Mon, April 19, 2010 12:47:15 PM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
   
 Hi Robert. Thanks so much for that my friend. 
 
 I have some problems with it though. You see I have an event in my app 
 applied to a button (refresh button) which resends data via the LinksService 
 i.e. LinksService. send and I've noticed that with your code if there is only 
 1 link i.e. 1 node and I click the refresh button it seems to keep recreating 
 that 1 over and over again as if it's recreating the same object in the array 
 collection or something. This doesn't happen if their are 2 or more 
 links/nodes/ objects. Perhaps I'll have to get the refresh button to empty 
 the array collection first before sending the data i.e. it's click function 
 would be LinksFullAC. flush; LinksService. send() Am I right?
 
 I've also noticed now with your code applied if I select an item in the 
 tilelist and click the reresh button I get the error Property categories not 
 found on String and there is no default value which is indicating the error 
 at the if statement in the code you gave me and the LinksService itself. Any 
 idea what's causing this?
 
 Another question though what if the xml contains no nodes? 
 
 You see my xml file is dynamic, I have a variable in my app called categoryid 
 and that variable is based on a category that the user selects in my app and 
 is submitted to getlinks.php which gets all the records from my mysql table 
 which contain that specific submitted categoryid and output them as the xml 
 file. Some categoryids have no records (the user can add and delte records 
 via my app). Is there any way of getting it to handle 0 records/nodes as well 
 as handling muliple records/1record which it seems to already do?
 
 Thanks so much for your help. Sorry to be a pain :-(
 
 --- In flexcod...@yahoogro ups.com, Robert Moss rdm0004@  wrote:
 
  This is not exactly how I would implement, but you should get the idea.  If 
  you have multiple category

Re: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread Robert Moss
Yes use a third if statement like:  if(event.result.categories)   
if(event.result.categories != null) should also work

Notice I used event.result instead of LinksService.lastResult.  Small change, 
but you should get in the habit as LinksService.lastResult will cause some pain 
in the future if you decide to change it's name for some reason.  

Amy suggested using e4x which is probably the correct answer as e4x grants you 
consistency ( you do not have the arrayCollection returned sometimes and 
ObjectProxy others) and allows you to work with XML in actionscript like XML 
was meant to be accessed.  You will still have to trap for the same issues, 
just implemented in a different way.   We do not always use e4x although we 
probably should, being lazy will probably bite us one of these days.





From: James garymoorcroft_...@yahoo.co.uk
To: flexcoders@yahoogroups.com
Sent: Mon, April 19, 2010 2:11:16 PM
Subject: [flexcoders] Re: Problems With my XML Created Array Collection

  
You were right about removeall (flush ha whoops) helping. I applied removeall 
before the if statements like you said and the first error is now gone.

The only problem I have now is the error which occurs when there are NO nodes 
in the xml i.e. all items have been removed and there are no values in my mysql 
table which relate to that specific category id.

I've changed the code to this:-

private function linksResultHandler( event:ResultEven t):void
{
LinksFullAC. removeAll( );
if(LinksService. lastResult. categories. category is ArrayCollection) {
LinksFullAC= LinksService. lastResult. categories. category as ArrayCollection;
}else if (LinksService. lastResult. categories. category is ObjectProxy)
{
var oCat:Object = new Object();
oCat.linkid = LinksService. lastResult. categories. category. linkid;
oCat.categoryid = LinksService. lastResult. categories. category. categoryid; 
oCat.label = LinksService. lastResult. categories. category. label;
oCat.icon = LinksService. lastResult. categories. category. icon;
oCat.link = LinksService. lastResult. categories. category. link;
LinksFullAC. addItem(oCat) ; 
}
}

The thing is though in that code I have the first if statement to check for if 
the result is an array collection which sets it as an array collection, the 
second if statement which if it is an object proxy adds the single object to 
the array collection but I think what I'll need is a third if statement which 
checks if the xml is empty/null or something and assign what will happen if it 
is null. Do you know of any way to do this and if so what do you think is best 
to set as the operation of such an if statement to make sure this error doesn't 
occur anymore? I thought it might be something like:-

if(LinksService. lastResult. categories. category is null)

but there seems to be no such thing. Any ideas?

Sorry to keep hassling but it's pretty much the last hiccup I've got in my app 
and I always try to pick the brains of guys who know their stuff as much as I 
can :-)

--- In flexcod...@yahoogro ups.com, Robert Moss rdm0...@...  wrote:

 In essence yes, I do not think I would do it as part of the button click, but 
 instead clear it before the IF in the result handler with LinksFullAC. source 
 = new Array();  or LinksFullAC. removeAll( );  I prefer the former. 
 
 As for your error, I'm not sure what's happening, but you should be able to 
 set a break in the result handler and see what is getting returned.  It looks 
 like for the combination you describe, categories is not getting returned for 
 some reason.  You'll need to figure out why and trap for it.  The same goes 
 for returning 0 records.  See what is getting returned and trap for it.
 
 
 
 
 
  _ _ __
 From: James garymoorcroft_ i...@...
 To: flexcod...@yahoogro ups.com
 Sent: Mon, April 19, 2010 12:47:15 PM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
 
 Hi Robert. Thanks so much for that my friend. 
 
 I have some problems with it though. You see I have an event in my app 
 applied to a button (refresh button) which resends data via the LinksService 
 i.e. LinksService. send and I've noticed that with your code if there is only 
 1 link i.e. 1 node and I click the refresh button it seems to keep recreating 
 that 1 over and over again as if it's recreating the same object in the array 
 collection or something. This doesn't happen if their are 2 or more 
 links/nodes/ objects. Perhaps I'll have to get the refresh button to empty 
 the array collection first before sending the data i.e. it's click function 
 would be LinksFullAC. flush; LinksService. send() Am I right?
 
 I've also noticed now with your code applied if I select an item in the 
 tilelist and click the reresh button I get the error Property categories not 
 found on String and there is no default value which is indicating the error 
 at the if statement in the code you gave me and the LinksService

[flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread James
I've noticed that if I remove all items from the mysql table which populates 
the remote xml file the xml that is produced is simply this:-

?xml version=1.0 ? 
categories / 

i.e. all of the nodes are removed so this means my app is looking for nodes 
that aren't actually there so it seems I need another else if bracket to deal 
with this but I haven't got a clue for how to check if an xml file is empty or 
null or whatever you'd call the above in flex and what to do within this else 
if bracket if it's not.

--- In flexcoders@yahoogroups.com, Robert Moss rdm0...@... wrote:

 In essence yes, I do not think I would do it as part of the button click, but 
 instead clear it before the IF in the result handler with LinksFullAC.source 
 = new Array();  or LinksFullAC.removeAll();  I prefer the former.  
 
 As for your error, I'm not sure what's happening, but you should be able to 
 set a break in the result handler and see what is getting returned.  It looks 
 like for the combination you describe, categories is not getting returned for 
 some reason.  You'll need to figure out why and trap for it.  The same goes 
 for returning 0 records.  See what is getting returned and trap for it.
 
 
 
 
 
 
 From: James garymoorcroft_...@...
 To: flexcoders@yahoogroups.com
 Sent: Mon, April 19, 2010 12:47:15 PM
 Subject: [flexcoders] Re: Problems With my XML Created Array Collection
 
   
 Hi Robert. Thanks so much for that my friend. 
 
 I have some problems with it though. You see I have an event in my app 
 applied to a button (refresh button) which resends data via the LinksService 
 i.e. LinksService. send and I've noticed that with your code if there is only 
 1 link i.e. 1 node and I click the refresh button it seems to keep recreating 
 that 1 over and over again as if it's recreating the same object in the array 
 collection or something. This doesn't happen if their are 2 or more 
 links/nodes/ objects. Perhaps I'll have to get the refresh button to empty 
 the array collection first before sending the data i.e. it's click function 
 would be LinksFullAC. flush; LinksService. send() Am I right?
 
 I've also noticed now with your code applied if I select an item in the 
 tilelist and click the reresh button I get the error Property categories not 
 found on String and there is no default value which is indicating the error 
 at the if statement in the code you gave me and the LinksService itself. Any 
 idea what's causing this?
 
 Another question though what if the xml contains no nodes? 
 
 You see my xml file is dynamic, I have a variable in my app called categoryid 
 and that variable is based on a category that the user selects in my app and 
 is submitted to getlinks.php which gets all the records from my mysql table 
 which contain that specific submitted categoryid and output them as the xml 
 file. Some categoryids have no records (the user can add and delte records 
 via my app). Is there any way of getting it to handle 0 records/nodes as well 
 as handling muliple records/1record which it seems to already do?
 
 Thanks so much for your help. Sorry to be a pain :-(
 
 --- In flexcod...@yahoogro ups.com, Robert Moss rdm0004@  wrote:
 
  This is not exactly how I would implement, but you should get the idea.  If 
  you have multiple category nodes, then your LinksService. lastResult. 
  categories. category is returned as an ArrayCollection and your code works. 
   If it only has one node then LinksService. lastResult. categories. 
  category is returned as an ObjectProxy.  So in your return method you could 
  have the following.
  
  if(LinksService. lastResult. categories. category is ArrayCollection) {
   LinksFullAC= LinksService. lastResult. categories. category as 
  ArrayCollection;
   }else
   {
   var oCat:Object = new Object();
  oCat.id = LinksService. lastResult. categories. category. id;
   oCat.label = LinksService. lastResult. categories. category. label;
   oCat.icon = LinksService. lastResult. categories. category. icon;
   LinksFullAC. addItem(oCat) ;  // NOTE: LinksFullAC needs to not 
  only be previously declared, but must also me instantiated with new 
  ArrayCollection( ) for this line to work.
  
   }
  
  
  
  
  
   _ _ __
  From: James garymoorcroft_ ict@
  To: flexcod...@yahoogro ups.com
  Sent: Mon, April 19, 2010 9:58:33 AM
  Subject: [flexcoders] Re: Problems With my XML Created Array Collection
  
  
  The thing is my xml is retrieved from a mysql database table which 
  sometimes will have no records or 1 record which will mean the xml will 
  have only 1 or no nodes which in turn causes the problem whereas sometimes 
  it has many records therefore the xml file would have many nodes which 
  would mean no problems.
  
  I've heard of looping but can't figure out how to do it or apply it to my 
  code. I've tried simply changing the array collection

Re: [flexcoders] Re: Problems With my XML Created Array Collection

2010-04-19 Thread Gary Moorcroft
Thanks a lot for your time Robert. You've been brilliant. I've just managed to 
find a similar solution somehwhere else but it's pretty much exactly the same 
as what you've suggested. I probably should use e4x too but t's the very fact 
that it needs to be implemented in a different way which puts me off. You're 
right about being consisten too by using event.result as this allows for easier 
modifications.
 
One problem that I seem to have in my code is the speed it takes to renew the 
dataprovider of the tilelist. Basically in my app the user can create new links 
remove links and update links which makes these changes directly to the mysql 
which obviously in turn feeds the xml file which populates the array 
collection/tilelist so these changes show in the app tilelist. The user can 
also switch between 9 different categories of links for all of the above 
actions. The thing is though each time the user clicks a category or does an 
action the app sends the request to the server which makes the change to the 
array collection but I've noticed that this takes a couple of seconds to 
refresh the tilelist data. So for example when the user is viewing the category 
1 links in the dataprovider and then clicks to category 2 it takes a few 
seconds to load this data but while it's being loaded the data from category 1 
is still there visible and selectable which I don't
 like at all.
 
Originally I wanted to have 9 tilelists each with different dataproviders but 
that seemed like overkill. Do you think it's best practice to have just 1 
tilelist? It's just the couple of seconds that it takes for it to switch from 1 
set of links to the next which I don't like.

--- On Mon, 19/4/10, Robert Moss rdm0...@yahoo.com wrote:


From: Robert Moss rdm0...@yahoo.com
Subject: Re: [flexcoders] Re: Problems With my XML Created Array Collection
To: flexcoders@yahoogroups.com
Date: Monday, 19 April, 2010, 21:00


  





Yes use a third if statement like:  if(event.result. categories)   
if(event.result. categories != null) should also work

Notice I used event.result instead of LinksService. lastResult.  Small change, 
but you should get in the habit as LinksService. lastResult will cause some 
pain in the future if you decide to change it's name for some reason.  

Amy suggested using e4x which is probably the correct answer as e4x grants you 
consistency ( you do not have the arrayCollection returned sometimes and 
ObjectProxy others) and allows you to work with XML in actionscript like XML 
was meant to be accessed.  You will still have to trap for the same issues, 
just implemented in a different way.   We do not always use e4x although we 
probably should, being lazy will probably bite us one of these days.





From: James garymoorcroft_ i...@yahoo. co.uk
To: flexcod...@yahoogro ups.com
Sent: Mon, April 19, 2010 2:11:16 PM
Subject: [flexcoders] Re: Problems With my XML Created Array Collection

  

You were right about removeall (flush ha whoops) helping. I applied removeall 
before the if statements like you said and the first error is now gone.

The only problem I have now is the error which occurs when there are NO nodes 
in the xml i.e. all items have been removed and there are no values in my mysql 
table which relate to that specific category id.

I've changed the code to this:-

private function linksResultHandler( event:ResultEven t):void
{
LinksFullAC. removeAll( );
if(LinksService. lastResult. categories. category is ArrayCollection) {
LinksFullAC= LinksService. lastResult. categories. category as ArrayCollection;
}else if (LinksService. lastResult. categories. category is ObjectProxy)
{
var oCat:Object = new Object();
oCat.linkid = LinksService. lastResult. categories. category. linkid;
oCat.categoryid = LinksService. lastResult. categories. category. categoryid; 
oCat.label = LinksService. lastResult. categories. category. label;
oCat.icon = LinksService. lastResult. categories. category. icon;
oCat.link = LinksService. lastResult. categories. category. link;
LinksFullAC. addItem(oCat) ; 
}
}

The thing is though in that code I have the first if statement to check for if 
the result is an array collection which sets it as an array collection, the 
second if statement which if it is an object proxy adds the single object to 
the array collection but I think what I'll need is a third if statement which 
checks if the xml is empty/null or something and assign what will happen if it 
is null. Do you know of any way to do this and if so what do you think is best 
to set as the operation of such an if statement to make sure this error doesn't 
occur anymore? I thought it might be something like:-

if(LinksService. lastResult. categories. category is null)

but there seems to be no such thing. Any ideas?

Sorry to keep hassling but it's pretty much the last hiccup I've got in my app 
and I always try to pick the brains of guys who know their stuff as much as I 
can :-)

--- In flexcod...@yahoogro ups.com