HTTPService XML: force ArrayCollections?

I'm loading an XML document with HTTPService.  It has an annoying behavior.  If the source XML looks like:
<one>
  <two>thing</two>
</one>
then one.two will be a String ("thing").
If the XML is:
<one>
   <two>thing</two>
   <two>another thing</two>
</one>
then one.two will be an ArrayCollection.
Is there a way to force the first case to also generate an ArrayCollection?  Right now I have to manually check everywhere if two is an ArrayCollection, if it isn't, make a new one, etc... Seems like Flex should take care of this automatically.
-jsd-

Hi,
Checkout the below code...this will ensure that you will get only ArrayCollection in both the cases...and also you need to check only once whether it is arrycollection or not and at other places you can avoid the check as you are converting it to ArrayCollection so you can directly use the arraycollection..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="loadXMLData();" layout="absolute">
<mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.rpc.xml.SimpleXMLDecoder;
   private var arrayCollection:ArrayCollection = new ArrayCollection();
   private function loadXMLData():void
    var xml:XML = new XML(myXml.toString());
    var xmlDoc:XMLDocument = new XMLDocument(xml);
    var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
    var resultObj:Object = decoder.decodeXML(xmlDoc);
    if(resultObj != null)
     if(resultObj.one.two is ArrayCollection)
      arrayCollection = resultObj.one.two as ArrayCollection;
     else if(resultObj.one.two is String)
      arrayCollection.addItem(resultObj.one.two);
  ]]>
</mx:Script>
<mx:XML id="myXml" xmlns="">
  <one>
    <two>thing</two>
  </one>
</mx:XML>
</mx:Application>
If this post answers your question or helps, please kindly mark it as such.
Thanks,
Bhasker Chari

Similar Messages

  • HTTP Service XML to ArrayCollection

    Hi,
    How do I convert the results from a remote XML List file
    called using the HTTPService method into an arrayCollection for
    sorting filtering etc. ??? (I assume it is the arrayCollection
    please feel free to suggest a better method)
    I have this working by calling the XML as a model that
    compiles at runtime, it'd be nice to have this work dynamically
    Thanks
    Rich

    If your data is in XML format, you may want to read it in as
    XML, and use an XMLList (or XMLListCollection wrapping the XMLList)
    to do the management of it.
    In terms of how to read it in at runtime (I assume that's
    what you're asking?) try something along these lines:
    internal var myXMLList:XMLList;
    internal function loadData() : void
    var XML_URL:String = "myData.xml";
    var myXMLURL:URLRequest = new URLRequest(XML_URL);
    var myLoader:URLLoader = new URLLoader();
    myLoader.addEventListener("complete", dataLoaded);
    try
    myLoader.load(myXMLURL);
    } catch(error:Error)
    trace("Failed to load Data");
    internal function dataLoaded(evtObj:Event) : void
    var myLoader:URLLoader = URLLoader(evtObj.target);
    var myXML:XML = XML(myLoader.data);
    myXMLList = myXML.ListedElement;
    }

  • (HTTPService - result="" - to ArrayCollection) -  a question for super expert ;)

    Firstly look at my example then you will read the question:
    Look at example below - I'm using HTTPService component to retrieve data from SQL database
    (read_record.php is generating nice and tidy xml file with my data)
    <!-- (A) read  -->
    <!-- =================== HTTP SERVICE (read_record) ============================ -->
        <mx:HTTPService id="readTimed"
            url="http://www.pudelek.pl/SCRIPT/A/read_record.php"
            result="patient(event)">
        </mx:HTTPService>
    Then 'result' is calling a function patient() which task is to assign 'event.result'
    to ArrayCollection called 'A_patient_dp'  (this ArrayCollection is a data provider
    for a specific data grid)
    private function patient(event:ResultEvent):void {
        trace("A - PATIENT - loaded...")
        trace(event.result.patient.patient)
        A_patient_dp = event.result.patient.patient
    Everything looks great here, data grid shows all the data from xml file generated
    by read_record.php
    and now is my problem :
    I don't want to display all the data, I want HTTPService to retrieve only particular data
    which are described by variable {parametr} - this var is generated by my application
    I've dond it this way:
    <!-- (A) MAP POSITIONING -->
    <!-- =================== HTTP SERVICE (read_record) ============================ -->
        <mx:HTTPService id="readRequestA"
            url="http://www.pudelek.pl/SCRIPT/A/A_send_read_record.php"
                useProxy="false"
                method="POST">
            <mx:request xmlns="">
                <idstaff>{parametr}</idstaff>
            </mx:request>
        </mx:HTTPService>
    I'm looking into source of 'A_send_read_record.php' in the internet browser and I see
    exact data tree (filtered) which I need.
    The problem here is : how to call function patient(event:ResultEvent) and give it
    data from the event to be assigned to ArrayCollection - like in first example.
    Thanks for all the ideas !!

    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services
    <mx:HTTPService id="readRequestA"
    url="http://www.pudelek.pl/SCRIPT/A/A_send_read_record.php"
    useProxy="false" result="patient(event)" method="POST">
      <mx:request xmlns="">
        <idstaff>{parametr}</idstaff>
      </mx:request>
    </mx:HTTPService>

  • HTTPService + XML Load + Memory Leak

    Hi all....
    I have noticed a memory leak in my application. This leak was
    not apparent when the application was completed some months back
    which is what left me a little confused as all I have done since
    was upgrade to Flex 3 and possibly updated / changed my Flash
    player.
    I think I have found the cause to this problem (below) but am
    not 100% sure that it is the "actual" problem or any reasons to
    back my thoughts up, so have listed what I have checked / tried
    along the way (maybe I have missed something)....
    My Discovery Process:
    I started profiling my application but did not find anything
    out of the ordinary. I did a code walk-through double checking I
    had cleaned up after myself, removing and even nulling all items
    etc but still to now success - the leak is still there.
    I have profiled the app in the profiler for reasonably long
    periods of time.
    All the classes etc being used within the app are consistent
    in size and instance amount and there is no sign of any apparent
    leak.
    I am using a HTTPService that is loading XML data which I am
    refreshing every 5 seconds. On this 5 second data refresh some
    class instances are incremented but are restored to the expected
    amount after a GC has occurred. The GC seems to take longer, the
    longer the app is running, therefore more and more instances are
    being added to the app, but when the GC eventually runs it "seems"
    to clear these instances to the expected amount.
    After scratching my head for a while I decided to make a copy
    of my application, rip everything out, and focus in my data load,
    where I found a problem!
    I have now just a HTTPService that loads an XML file every 5
    seconds, and this is all I currently have in the app (as I ripped
    the rest of the code out), e.g:
    Code:
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    ....... creationComplete="initApp()" >
    <mx:HTTPService
    id="httpServiceResults"
    url="
    http://myIP:myPort/myRoot/myXML.cfm"
    resultFormat="e4x"
    result="httpResultHandler(event)" />
    <script....... >
    private var timerPulse:Timer;
    private function initApp():void
    httpServiceResults.send();
    timerPulse = new Timer(5000, 0);
    private function httpResultHandler(event:ResultEvent):void
    timerPulse.start();
    timerPulse.addEventListener(TimerEvent.TIMER, timerRefresh);
    public function timerRefresh(eventObj:TimerEvent):void
    timerPulse.stop();
    timerPulse.removeEventListener(TimerEvent.TIMER,
    timerRefresh);
    timerPulse.reset();
    httpServiceResults.send();
    </script>
    </mx:Application>
    This is pretty much the code I am currently using and it
    leaks.
    I ran and monitored this in both the profiler and the
    activity / task manager, and after running the app for 1800 seconds
    (30 min) in the profiler, the memory size grew from 50mg to 165mg
    just sending the HTTPService.
    I tried loading the service in multiple ways including in AS
    rather than MXML creating new instances of it each time, resetting
    it, nulling it etc... but nothing prevented this memory increase.
    I then tried to load the XML using different methods such as
    using the URLRequest and URLLoader which again caused a memory
    leak.
    What still confuses me is that this leak did not exist in the
    previous version and not a great deal has changed since then apart
    from upgrading to Flex 3 and possibly upgrading my Flash payer
    (which I believe is a possible cause)
    After looking into this issue a bit more deeply, I read a few
    blogs / forums and other people are experiencing the same problems
    - even with a lot bigger leaks in some cases all when reloading
    large sets of XML data into Flex - however, I as of yet found no
    solution to this leak - people with a similar problem believe it is
    not due to a memory leak more a GC error, and others pointing
    towards the Flash Player itself that is leaking - I don't really
    know.
    Findings so far during investigation of this issue:
    * App leaks for both HTTPService and ULRRequest / URLLoader
    methods
    * App only leaks when calling a data loader
    * The size of the leak seems to depend on the size of the
    XML being loaded
    * The size of the leak also seems to be affected by the
    applications heaviness - the greater seems to enhance the leak
    An interesting factor I have noticed is that if I copy the
    XML from my "myXML.cfm" that I link to in my HTTPService and copy
    the contents of the file into my own XML file stored within the
    Flex project root itself: ""myXML.xml"" the leak disappears... like
    it seems to link when loading the XML over a network, however as my
    network knowledge is not great I am not sure what to make of this -
    any ideas???
    Could the connection to the XML document cause leaks??? is
    there anything else that could cause this leak??? have I something
    in my code sample that could cause this leak??? or could any of the
    other things I have mentioed cause this leak???
    Any help / ideas would be greatly appreciated.
    Thanks,
    Jon.

    I also observed heavy memory leak from using httpservice with
    XML data. I am using Flex3 builder under Linux. My Flex application
    polls httpservice every 10 seconds. The reply is a short XML
    message less than 100 bytes. This simple polling will consume 30+
    MB of memory every hour. I leave it idling for several hours and it
    took 200 MB of memory. No sign of garbage collection at all.

  • How do I create a line chart direct from xml or convert xml to ArrayCollection

    The xml is simple:
    <data>
    <row name="Q1">
    <expenses>64</expenses>
    <revenue>98</revenue>
    <profit>34</profit>
    </row>
    <row name="Q2">
    <expenses>44</expenses>
    <revenue>28</revenue>
    <profit>64</profit>
    </row>
    <row name="Q3">
    <expenses>14</expenses>
    <revenue>58</revenue>
    <profit>54</profit>
    </row>
    </data>
    it's dynamically generated as a string so could be created in xml format, or ArrayCollection, or any other format that works. However I can't find a example of using xml as the datasource that works. I've tried to convert it to an ArrayCollection first but that didn't work either.
    Alternatively I could store the data as a string "Month: "May", Profit: 2400, Expenses: 575, Amount: 456", then:
    expensesAC2.addItem({Month: "May", Profit: 2400, Expenses: 575, Amount: 456 });
    works but:
    var settings:String = resultXML.row[0];
    expensesAC2.addItem({settings});
    doesn't work. Any suggestions, or links to a tutorial that works would be really appreciated?

    Hi all,
    This issue was resolved off-line, however, I wanted to note a few points that were shared with me.
    Learnings from Forum discussion:
    Best practice is to use a combination of INDEX and MATCH functions instead of Vlookups.  Using the VLOOKUP function can result in a very slow dashboard if using a lot of data. 
    Also, when using the Filter Component note the destination field as the filter component does not copy the first filter value at all so you have to adjust by one column to accommodate for this (two columns if you have 3 filters etc).

  • Help needed: HTTPService, XML, Repeater

    Hi there
    I am very much new to Flex 2 technology and require help
    regarding HTTPService and XML.
    In my main application (NestedRepeater.mxml), I have the
    following code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns:comps="component.*" layout="absolute"
    creationComplete="userRequest.send()">
    <mx:HTTPService id="userRequest"
    url="/Users/ronnyk/Sites/book.xml" useProxy="false" method="POST"
    />
    <mx:VBox>
    <mx:Repeater id="Repeater1"
    dataProvider="{userRequest.lastResult.book.section}">
    <comps:Section
    sectionNumber="{Repeater1.currentItem.sectionnumber}"
    xmlSection="{Repeater1.currentItem}" />
    </mx:Repeater>
    </mx:VBox>
    </mx:Application>
    In my real app, I have a PHP script as the url for the
    HTTPService, but for the sake of simplicity, I'll just use
    book.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <book>
    <section>
    <sectionnumber>s1</sectionnumber>
    <chapter>
    <chapternumber>c1</chapternumber>
    </chapter>
    <chapter>
    <chapternumber>c2</chapternumber>
    </chapter>
    </section>
    <section>
    <sectionnumber>s2</sectionnumber>
    <chapter>
    <chapternumber>c3</chapternumber>
    </chapter>
    </section>
    </book>
    As you can see as well, I have a custom component called
    Section.mxml within the repeater of the main app, the custom
    component is as follows:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    [Bindable]
    public var xmlSection:XML;
    [Bindable]
    public var sectionNumber:String;
    ]]>
    </mx:Script>
    <mx:VBox>
    <mx:Panel id="panel1" layout="absolute" title="Section"
    width="166" height="70">
    <mx:VBox>
    <mx:Label text="{this.sectionNumber}"/>
    </mx:VBox>
    </mx:Panel>
    <mx:Repeater id="Repeater2"
    dataProvider="{xmlSection.chapter}">
    <mx:Panel layout="absolute" title="Chapter" height="100"
    width="166">
    <mx:Label text="{Repeater2.currentItem.chapternumber}"
    />
    </mx:Panel>
    </mx:Repeater>
    </mx:VBox>
    </mx:Canvas>
    I am passing xmlSection="{Repeater1.currentItem}" to the
    custom component so that I can correctly create nested children for
    each parent. But anyway, my problem happens when I include
    xmlSection="{Repeater1.currentItem}" to the custom Section
    component, it always displays only one section (the label "s1"
    doesn't even appear), but if I exclude
    xmlSection="{Repeater1.currentItem}", when I run it, it displays
    correctly:
    s1
    s2
    Any help/suggestion would be greatly appreciated as I am at
    my wits end regarding my project.
    Let me know if you need any more info.
    Thanks!

    Hi again,
    After going through the HTTPService topic forum, I should be
    using resultHandler for my HTTPService, so I change my main mxml
    app into:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns:comps="component.*" layout="absolute"
    creationComplete="userRequest.send()">
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var myData:XML;
    private function resultHandler(event:ResultEvent):void {
    myData = event.result.book.section as XML;
    ]]>
    </mx:Script>
    <mx:HTTPService id="userRequest"
    url="/Users/ronnyk/Sites/book.xml" resultFormat="e4x"
    result="resultHandler(event)" useProxy="false" method="POST" />
    <mx:VBox>
    <mx:Repeater id="Repeater1" dataProvider="{myData}">
    <comps:Section
    sectionNumber="{Repeater1.currentItem.sectionnumber}"
    xmlSection="{Repeater1.currentItem}" />
    </mx:Repeater>
    </mx:VBox>
    </mx:Application>
    But now, when I run it, it displays nothing, just a blank
    browser. Can someone please help? Maybe because I shouldn't use
    creationComplete="userRequest.send()" in the Application tag?
    Thanks!

  • XML to ArrayCollection

    What is the most elegant way to populate an ArrayCollection
    with XML content?
    I would do that with a for loop that would go through all XML
    nodes, create an object for each node and add this object into an
    ArrayCollection object, but is this the best solution?
    Any help would be fantastic!
    Thank you!
    EDIT: Or is there an elegant way to populate an
    ArrayCollection from a String containing XML formated
    content?

    Why do you want to do that? There is very rarely a good
    reason for this.
    Tracy

  • Accessing HTTPService xml attributes

    i have an HTTPService isntalled which gets an xml document,
    something like this
    <item>
    <doc name="x" url="htttp://www.yyy.com" />
    <doc name="x" url="htttp://www.yyy.com" />
    <doc name="x" url="htttp://www.yyy.com" />
    </item>
    i want to display each doc tag in a list component with
    attribute -->name<--, now as far as it goes i can only get
    the list
    to display: [object Object] and this is what my dataProvider
    for list components looks like:
    dataProvider="{service.lastResult.item.doc}" i have trid
    every single trick but i cannnot get the list to show the name
    attribute of each of those tags or even the url tag. what is the
    solution to this?

    iquaaani's approach is what I would also suggest, especially
    resultFormat="e4x". However, I don't advise binding directly to
    lastResult because it is hard to debug. Instead, use a handler
    function called by the result event.
    In that handler, do something like:
    var xmlREsult:XML = XML(event.result);
    trace(xmlResult.toXMLString());
    This will show you exactly what your result xml looks like,
    so you will know how to write the access expression.
    See this for more info on using XML:
    http://livedocs.macromedia.com/flex/2/docs/00001910.html
    Tracy
    Tracy

  • HTTPService XML contentType and Gets

    I have a flex front-end in which I'm trying to get data from
    a back-end using an HTTPService. I would like the service to use a
    GET, and make the request using the contenttype of application/xml.
    So for example here's an HTTPService that does this:
    <mx:HTTPService id="testService"
    url="/blah/list"
    contentType="application/xml"
    method="GET"/>
    When I go ahead and do the request (using testService.send())
    it always does the request as a POST. If I change the HTTPService's
    contentType to "application/x-www-form-urlencoded" it works
    correctly as a GET.
    Does anyone have any pointers on how I could get this to work
    the way I want it? Is this a flex bug or an undocumented feature
    somewhere? Any workarounds?
    Thanks.
    Here is the output I get when I put an <mx:TraceTarget>
    in the app with the contentType="application/xml":
    (mx.messaging.messages::HTTPRequestMessage)#0
    body = "<>"
    clientId = (null)
    contentType = "application/xml"
    destination = "DefaultHTTP"
    headers = (Object)#1
    httpHeaders = (Object)#2
    messageId = "3EB110BB-955A-9601-C595-C14D38E12C14"
    method = "POST"
    recordHeaders = false
    timestamp = 0
    timeToLive = 0
    url = "/pools/list"

    I think I may have been confused on the way flex goes about
    handling data requests. The final outcome I was looking for was
    that requests hitting the server from the flex app would have the
    accept type of 'application/xml' (so you'd do a .send() on the
    service and it would send out a request who's header would be ...
    Accept: application/xml).
    I was assuming that this parameter would change that, but I'm
    getting the feeling that that is more of an internal to the app
    setting than an outbound request parameter and that the browser
    will probably keep the same request header no matter what.
    So if you're running your flex app on Firefox your server is
    always going to see (for the time being)
    Accept:
    text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png ,*/*;q=0.5
    Hopefully that is clear.
    Anyone want to confirm/deny that?

  • HTTPService/XML issue

    Hey fellow Flexers
    I'm a relative newb to Flex so there is probably a simple
    solution to my issue, but I've been trying to fix this for hours
    now with no success.
    I'm loading in some XML using HTTPService and accessing the
    parameters without any issue, it's the node value I have issues
    with.
    The XML is in the following format:
    <events>
    <comment up="1">Some text goes here 1</comment>
    <comment up="3">Some text goes here 2</comment>
    </events>
    Now, with my current code I can access the 'up' parameter,
    but I can't seem to get to the actual node value. i.e "Some text
    goes here.."
    My code:
    <mx:HTTPService id="dataRequest" url=myURL/>
    <mx:Panel>
    <mx:DataGrid
    dataProvider="{dataRequest.lastResult.events.comment}">
    <mx:columns>
    <mx:DataGridColumn headerText="Title"
    dataField="comment"/> <<**this line is the issue**
    <mx:DataGridColumn headerText="Up" dataField="up"/>
    << this line works fine
    </mx:columns>
    </mx:DataGrid>
    <mx:Panel>
    I've chopped out some of the code to make it readable. I know
    that the code is incorrect but I've tried dozens of variations to
    get it working but I'm having no joy.
    Any ideas?
    Thanks in advance.
    Paul

    Suggestions:
    1) Use resultFormat="e4x" on the HTTPService tag. The default
    is object, which causes Flex to convert the xml into a nested
    object structure. God only knows the result of that.
    2) Do not bind to the result. Use a result handler, so you
    can debug the data.
    Here are some code snippets below.
    Tracy
    Sample code using HTTPService, e4x, handler function to
    populate a list item.
    Also shows usage of AsyncToken.
    The DataGrid tag:
    <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}"
    .../>
    The HTTPService tag:
    <mx:HTTPService id="service" resultFormat="e4x"
    result="onResult(event)" fault="..../>
    Script block declaration:
    import mx.rpc.Events.ResultEvent;
    [Bindable]private var _xlcMyListData:XMLListCollection;
    Invoke send:
    var oRequest:Object = new Object();
    oRequest.Arg1 = "value1";
    var callToken:AsyncToken = service.send(oRequest);
    token.callId = "myQuery1";
    Result Handler function:
    private function onResult(oEvent:ResultEvent):void {
    var xmlResult:XML = XML(event.result); //converts result
    Object to XML. can also use "as" operator
    var xlMyListData:XMLList = xmlResult.myListData; //depends
    on xml format, is row data
    _xlcMyListData = new XMLListCollection(xlMyListData); //wrap
    the XMLList in a collection
    trace(_xlcMyListData.toXMLString()); //so you can see
    exactly how to specify dataField or build labelFunction
    var callToken:AsyncToken = oEvent.token;
    var sCallId = callToken.callId; //"myQuery1"
    switch(sCallId) {
    case "myQuery1":
    doQuery2();
    break;
    }//onResult

  • Passing data from an XML object to an itemRenderer

    I'm trying to color the background of a column in a datagrid and have found a sample file that illustrate the concept. However, the sample has data stored in an arrayCollection whereas mine is in an XML object. The problem is that the data in the sample file is apparently automatically passed to the itemRenderer (shown below: note the trace statement). My XML object does not appear to automatically pass data to the itemRenderer. So my questions are:
    1. Is there a simple way to pass data stored in an XML object to an itemRenderer
    or
    2. Should I convert my XML to an arrayCollection? If so, what's the best way to do this-- I've tried the following, but without success:
    <mx:Model id="xmldata" source="example3.xml"/>
      <mx:ArrayCollection id="myAC" source="{ArrayUtil.toArray(xmldata.Example1)}" />
    Here's what the xml looks like:
    <TABLE>
       <EXAMPLE1>
          <difficulty> 0.5 </difficulty>
          <discrimination> 0.7 </discrimination>
          <item> 3 </item>
       </EXAMPLE1>
    </TABLE>  
    Here's the itemRenderer:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">
        <!--
            This item renderer simply extends Label and overrides the updateDisplayList function to
            draw a gradient-filled rectangle. The colors in the gradient are determined from the
            data.
        -->
        <mx:Script>
        <![CDATA[
            import flash.geom.Matrix;
            import flash.display.GradientType;
            import flash.display.Graphics;
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                super.updateDisplayList(unscaledWidth,unscaledHeight);
                var m:Matrix = new Matrix();
                m.createGradientBox(unscaledWidth,unscaledHeight);
                var g:Graphics = graphics;
                            trace("data.col3="+data.col3)
                var colors:Array = (data.col3 < 2000 ? [0x0000CC,0x0000FF] : [0x00CC00,0x00FF00]);
                g.clear();
                g.beginGradientFill(GradientType.LINEAR, colors, [0.2,0.6], [0,255], m);
                // the rectangle is drawn a little high and a little tall to compensate for the gap
                // the DataGrid introduces between rows.
                g.drawRect(0, -2, unscaledWidth, unscaledHeight+4 );
                g.endFill();
        ]]>
        </mx:Script>
    </mx:Label>

    This sample code should answer your question of how to bring data into the renderer automatically. It comes in via the DataGrid dataProvider and then you refer to it in the renderer as data.XYZ, where XYZ is the field in the XML with the data. See FB 3 help sys on e4x syntax.
    ------------------ mainapp.mxml --------------------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      creationComplete="srvc.send();">
      <mx:Script>
        <![CDATA[
          import mx.rpc.events.ResultEvent;
          import mx.collections.XMLListCollection;
          [Bindable] private var xlc:XMLListCollection;
          private function dataHandler(evt:ResultEvent):void{
            xlc = new XMLListCollection(evt.result..EXAMPLE1 as XMLList);
        ]]>
      </mx:Script>
      <mx:HTTPService id="srvc" url="data2.xml" result="dataHandler(event)"
        resultFormat="e4x"/>
      <mx:DataGrid dataProvider="{xlc}">
        <mx:columns>
          <mx:DataGridColumn headerText="Difficulty" dataField="difficulty"/>
          <mx:DataGridColumn headerText="Discrimination" dataField="discrimination"/>
          <mx:DataGridColumn headerText="Item" itemRenderer="MyLabel"/>
        </mx:columns>
      </mx:DataGrid>
    </mx:Application>
    ----------- MyLabel.mxml --------------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
        <![CDATA[
          import flash.geom.Matrix;
          import flash.display.GradientType;
          import flash.display.Graphics;
          override protected function updateDisplayList(unscaledWidth:Number,
            unscaledHeight:Number):void{
            super.updateDisplayList(unscaledWidth,unscaledHeight);
            this.text = data.col3;
            var m:Matrix = new Matrix();
            m.createGradientBox(unscaledWidth,unscaledHeight);
            var g:Graphics = graphics;
            var colors:Array = (data.col3 < 2000 ? [0x0000CC,0x0000FF] : [0x00CC00,0x00FF00]);
            g.clear();
            g.beginGradientFill(GradientType.LINEAR, colors, [0.2,0.6], [0,255], m);
            g.drawRect(0, -2, unscaledWidth, unscaledHeight+4 );
            g.endFill();
        ]]>
      </mx:Script>
    </mx:Label>
    ------------ data2.xml ----------------
    <?xml version="1.0" encoding="utf8"?>
    <TABLE>
       <EXAMPLE1>
          <difficulty> 0.5 </difficulty>
          <discrimination> 0.7 </discrimination>
          <col3> 3 </col3>
       </EXAMPLE1>
    </TABLE>

  • Comparison of number of bytes transferred over network while using HTTPService and RemoteObjects

    If I have to transfer data(say records of 100 employees in a DB) from Server to Client, I could use HTTPService and fetch the data as an XML file and then convert it to ArrayCollection in the Client. Or use RemoteObject and transfer the data in binary. Lets ignore other methods(Web Services etc) of data transfer for the moment.
    Now, for the same data, if I implement the application using HTTPService and RemoteObject, I notice that the number of bytes transferred over the network is less in case of HTTPService(XML) when compared to RemoteObject(AMF) which is a shock to me. My understanding is that AMF transfer should be more compact than XML. Ofcourse, once the data is available, RemoteObject result processing is noticeably faster than HTTPService result processing. My concern is why data transferred using AMF is larger than XML. As an example, you may refer to the samples provided in TourDeFlex. Refer to the following:
    HTTPService:
        Found in : Flex Data Access->HTTPService->BasicExample
        Link: http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=0;sampleId =12700
        Click on the 'Get Data' button to fetch the data.
        Bytes transferred - 1050
    RemoteObject:
        Found in : Flex Data Access->RemoteObject->BasicJavaRemoting
        Link: http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=0;sampleId =13300
        Click on the 'Get Data' button to fetch the data.
        Bytes transferred - 1440
    This is a significant size difference. You may see the data transfer size by using developer tools like the HTTPFox Firefox extension.
    Am I missing something here? Any help will be very much appreciated.
    Thanks,
    Balu

    There is definitely problem with your tool or you looked at something else. Please check the attached snapshots of the session using charles capture tool. The response sizes are way bigger than what you mentioned but remoteobjects is almost half of httpservice for the complete transfer including request and response. Check below -
    httpservice -
    http://tinypic.com/view.php?pic=2q2le2e&s=7
    amf -
    http://tinypic.com/r/10wmx4o/7

  • Sorting XML Data

    Hi, I didn't want to bury this in the previous thread. The
    Doc examples seem to show this process by creating an array in the
    code. How do I?:
    • Convert the data from an XML file pulled using
    HTTPService into an arrayCollection? (I think that's what I'm
    supposed to do)
    • Sort the data based on chosen field like
    • Display the sorted data (or a way to call it)
    That's it. ! I think there should be more of this covered in
    the docs and definitely an article/quick start ;) Cheers
    Macradobe

    if you don't want to convert the xml dom to your own datastructures, you could use xslt and the sort element:
    http://www.w3schools.com/xsl/xsl_sort.asp

  • Add a for each script to loop through HTTPService?

    I'm using Flash Builder 4 with the Flex 4.1 SDK.  I want to add a "for each" script to loop through my HTTPService XML file so only each nepName displays only once in my dropdown list.  In my XML file I have multiple records associated with nepName.  I would like ALL the records associated with each nepName to populate in my datagrid when it is selected from the dropdown.  Currently in my dropdown there is a nepName entry for each XML tag.  I hope I was able to explain that well enough. I'll try to put my code below so you can see everything I'm working with.
    MXML:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:esri="http://www.esri.com/2008/ags"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                   creationComplete="nepInfo.send()">
        <s:layout>
            <s:VerticalLayout horizontalAlign="center" paddingTop="25"/>
        </s:layout>
        <fx:Declarations>
            <s:HTTPService id="nepInfo" url="http://www.epa.gov/owow/estuaries/nep_info.xml"/>
            <!--s:RadioButtonGroup id="optiongroup"/-->
        </fx:Declarations>
        <s:Panel title="NEP Project Information">
            <s:layout>
                <s:VerticalLayout/>
            </s:layout>
            <s:HGroup verticalAlign="middle">
        <mx:Form x="188" y="34" width="338">
        <mx:FormItem label="Search for NEP Information:">
        <s:DropDownList enabled="true" id="dropDownList" prompt="Select NEP" dataProvider="{nepInfo.lastResult.records.record}" labelField="nepName">
        </s:DropDownList>
        </mx:FormItem>
        </mx:Form>       
            </s:HGroup>   
            <mx:DataGrid id="resultsGrid"
                         dataProvider="{dropDownList.selectedItem}"
                         visible="{dropDownList.selectedItem != null}" x="20" y="62" width="1166" height="620">
                <mx:columns>
                    <mx:DataGridColumn dataField="projectName" headerText="Project Name" wordWrap="true"/>
                    <mx:DataGridColumn dataField="projectDescription" headerText="Project Description" wordWrap="true"/>
                    <mx:DataGridColumn dataField="acres" headerText="Acres" wordWrap="true"/>
                    <mx:DataGridColumn dataField="habitatDescription" headerText="Habitat Description" wordWrap="true"/>
                    <mx:DataGridColumn dataField="neportCategory" headerText="Habitat Category" wordWrap="true"/>
                    <mx:DataGridColumn dataField="restorationType" headerText="Restoration Type" wordWrap="true"/>
                    <mx:DataGridColumn dataField="leadPartner" headerText="Lead Partner" wordWrap="true"/>
                </mx:columns>
            </mx:DataGrid>
        </s:Panel>
    </s:Application>
    XML: http://www.epa.gov/owow/estuaries/nep_info.xml
    Thank you in advance for your help!
    -Alison

    ($file, pwd);Assuming "pwd" is meant as the current directory, here a small example :
    TEST@db102 SQL> create or replace procedure test_proc (p1 varchar2, p2 varchar2)
      2  is
      3  begin
      4     dbms_output.put_line (p1||' '||p2);
      5  end;
    TEST@db102 SQL> /
    Procedure created.
    TEST@db102 SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    $ ls -l /tmp/test/*.sql
    -rw-r--r--  1 ora102 dba  69 Apr 18 23:23 /tmp/test/file1.sql
    -rw-r--r--  1 ora102 dba 112 Apr 18 23:23 /tmp/test/file2.sql
    -rw-r--r--  1 ora102 dba 120 Apr 18 23:23 /tmp/test/file3.sql
    $ cat test_proc.sh
    DIR=/tmp/test
    cd $DIR
    ls *.sql | while read file
    do
            echo "Processing file $file"
            sqlplus -s test/test << EOF
    set feed off
    set pages 0
    set serveroutput on
    exec test_proc('$file', '`pwd`');
    exit
    EOF
    done
    $ ./test_proc.sh
    Processing file file1.sql
    file1.sql /tmp/test
    Processing file file2.sql
    file2.sql /tmp/test
    Processing file file3.sql
    file3.sql /tmp/test
    $

  • How to create Bar chart  from existing XML file

    Hi all,
    i'm new to flex, i need your help to develop a flex for
    dashboard app. we have sample.xml file. by using this i need to
    create a bar diagram or piechart.
    Please help me out
    The XMl looks like this.....
    <?xml version="1.0" encoding="utf-8"?>
    <user id="123412343">
    <fullName>
    <lastName>Telles</lastName>
    <firstName>vijay</firstName>
    </fullName>
    <preferences>
    <modWidth>235</modWidth>
    <modHeight>250</modHeight>
    <totalWidth>1650</totalWidth>
    <totalHeight>1650</totalHeight>
    <modsX>4</modsX>
    <modsY>2</modsY>
    </preferences>
    <module id="Status2">
    <windowOpen>true</windowOpen>
    <pointsToShow>
    <p label="Proposed"/>
    <p label="Draft"/>
    <p label="DEP Adpt"/>
    <p label="EPA Adpt"/>
    </pointsToShow>
    <dataSetsToShow>
    <label>2006</label>
    <label>2007</label>
    </dataSetsToShow>
    </module>
    </user>

    convert this xml to ArrayCollection called chartData
    var charOption:String = "totalHeight"; /Use this to set the
    yField property...
    <mx:ColumnChart showDataTips="true" id="barChart"
    width="100%" height="100%" dataProvider="{chartData}"
    color="0xffffff">
    <mx:horizontalAxis>
    <mx:CategoryAxis
    dataProvider="{chartData}"
    categoryField="hour" />
    </mx:horizontalAxis>
    <mx:verticalAxis>
    <mx:LinearAxis labelFunction="addDollarSign"/>
    </mx:verticalAxis>
    <mx:series>
    <mx:ColumnSeries yField="{chartOption}"
    showDataEffect="interpolate"
    creationCompleteEffect="interpolate"/>
    </mx:series>
    </mx:ColumnChart>

Maybe you are looking for

  • How to add new fields in the Create Suppport Message Screen

    Hi experts, I have a requirement which is to add 3 selection fields in the Create Support Message Screen. The 3 fields are Category, Subject and Solution. The value of these 3 fields must aurtomaticallly populate the same fields in the Support Messag

  • Transfer from iPod to Computer

    I returned my old computer before saving the library to my iPod. I did however export the library, so I have it on my new computer hard drive. Is there anyway I can import it to the library on my new computer so it will reflect my iPod? If not, what

  • Apps will not download or update consistently still

    I have had this issue for quite some time and researched to find others with similar issues but no solutions. Latest 11.3.0.54 version (but this happens with previous versions as well, not a new issue but potentially worse) Windows 8.1 I tell itunes

  • JvmTI agent problem

    My jvm agent as follows: JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)   // simple code printf("Test for jvm agent \n"); return 0; JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) // nothing to do. 2. and my makefil

  • IMac OSX 10.9.5 Shows Brother MFC 8710DW Printer Is "Offline" and "Not Connected T

    I have a Brother MFC 8710 DW that I've had for the past 4 months. It works perfectly fine with my other devices (iPad, iPhone, Windows PC and Macbook Pro) but it doesn't work with my iMac OSX 10.9.5. I did the things listed below but it keeps on tell