0

I am trying to filter xml data but right now I there are no data appearing in the list. Am I doing something wrongly? Sorry guys I am still new to this website too. Pardon me If I posted the wrong way.

This is the error.

TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@51443c1 to XMLList.

    xmlns:s="library://ns.adobe.com/flex/spark" title="Malls"

    creationComplete="malls.send()">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:HTTPService id="malls" url="assets/details.xml" 
                   result="malls_resultHandler(event)"/>
</fx:Declarations>

<fx:Script>
    <![CDATA[
        import mx.collections.XMLListCollection;
        import mx.rpc.events.ResultEvent;
        [Bindable]
        private var ml:XMLListCollection;

        private function malls_resultHandler(Event:ResultEvent):void
        {
            ml = new XMLListCollection(malls.lastResult.list.mallD);

        }

        private function filterDemo():void{
            ml.filterFunction=searchDemo;
            ml.refresh();
        }

        private function searchDemo(item:Object):Boolean{
            var isMatch:Boolean=false;
            if(item.name.toLowerCase().search(search.text.toLowerCase())!=-1){
                isMatch=true;
            }
            return isMatch;
        }


    ]]>
</fx:Script>


<s:navigationContent/>
<s:titleContent>
    <s:TextInput id="search" change="filterDemo()" x="10" y="10" prompt="Search"/>
</s:titleContent>

<s:List id="list" top="0" bottom="0" left="0" right="0"
        dataProvider="{ml}"
        change="navigator.pushView(MallsDetails, list.selectedItem)">
    <s:itemRenderer>
        <fx:Component>
            <s:IconItemRenderer
                label="{data.name}"/>
        </fx:Component>
    </s:itemRenderer>
</s:List>

  • show your XML struture too – Raja Jaganathan Feb 17 '14 at 05:55
  • 1 Ion Orchard
    2 Orchard Turn
    Singapore 238801 +65 6238 8228 customercare@ionorchard.com.sg Ion.png
    –  Feb 17 '14 at 06:55
  • 1. Oh.. would be nice to actually post your XML inside your question. 2. If you already have XML why not use XML stuff instead of array collection. Please update your post to get better visibility. – Adrian Pirvulescu Feb 17 '14 at 09:25

2 Answers2

0

You can try to replace

ml = new XMLListCollection(malls.lastResult.list.mallD);

by

var xmllist:XMLList = XMLList (malls.lastResult.list.mallD);
ml = new XMLListCollection(xmllist);
  • Thank you for your help. But however, The structure of the xml data is there but the data is not being displayed. –  Feb 17 '14 at 07:01
  • Thanks! However, there doesn't seems to have any data in the list –  Feb 17 '14 at 07:39
0

Try this,

We needn't mention XML root tag name here so just get rid of list tag name when access XML.

Add resultFormat="e4x" to HTTPService component.

<s:HTTPService id="malls" url="assets/details.xml" resultFormat="e4x"
                   result="malls_resultHandler(event)"/>


ml = new XMLListCollection(malls.lastResult.mallD);

To

var response:XML = malls.lastResult as XML;

var mallIDXMLList:XMLList = response.mallD;             
m1 = new XMLListCollection(mallIDXMLList);
Raja Jaganathan
  • 33,099
  • 4
  • 30
  • 33
  • Thanks! However, there doesn't seems to have any data in the list. –  Feb 17 '14 at 07:31
  • Answer updated please check out. Also make sure your malls.lastResult as well defined XML I assume you xml like this ......... – Raja Jaganathan Feb 17 '14 at 07:44
  • Yup everything is actually perfect. why does m1 is not being found right now? Description Resource Path Location Type 1120: Access of undefined property m1. Malls.mxml /SGshopping/src/views line 26 Flex Problem –  Feb 17 '14 at 07:51
  • I am sorry it should ml. I wrote it wrongly. I tried retyped the dataProvider but right now I have this problem. TypeError: Error #1009: Cannot access a property or method of a null object reference. –  Feb 17 '14 at 07:59
  • where that error exactly happened.Can you pls point out line. – Raja Jaganathan Feb 17 '14 at 08:07
  • TypeError: Error #1009: Cannot access a property or method of a null object reference. at views::Malls/malls_resultHandler()[C:\Users\Taro\Adobe Flash Builder 4.6\SGshopping\src\views\Malls.mxml:23] at views::Malls/__malls_result()[C:\Users\Taro\Adobe Flash Builder 4.6\SGshopping\src\views\Malls.mxml:10] –  Feb 17 '14 at 08:10
  • Answer updated.Problem is malls.lastResult as XML it always returns null due to it is default object type so you need to set resultFormat as e4x format for httpservice component then it will fine. – Raja Jaganathan Feb 17 '14 at 08:29
  • Sorry for the late reply! It is working. Thank you so much and your time for being patient! –  Feb 18 '14 at 12:58
  • I'm Glad too, If answer is useful please accepts as answer [click tick icon] and give up vote just clicking UP Arrow before Tick Icon.So that other people interest to answer your question. – Raja Jaganathan Feb 18 '14 at 13:37