0
votes

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>

2
show your XML struture too - Raja Jaganathan
<list> <mallD> <id>1</id> <name>Ion Orchard</name> <address>2 Orchard Turn</address> <time>10am - 10pm</time> <pcode>Singapore 238801</pcode> <officePhone>+65 6238 8228</officePhone> <email>[email protected]</email> <picture>Ion.png</picture> </mallD> - user2648243
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

2 Answers

0
votes

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);
0
votes

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);