开发者

Can't understand the exception in Flex?

开发者 https://www.devze.com 2022-12-15 05:52 出处:网络
I was trying the flickr code provided in the learn.adobe.com website, and I am getting this exception:

I was trying the flickr code provided in the learn.adobe.com website, and I am getting this exception:

[RPC Fault faultString="Error #1090: XML parser failure: element is malformed." faultCode="Client.CouldNotDecode" faultDetail="null"]
    at mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:851]
    at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:188]
    at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
    at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
    at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

I can't understand this exception. Can anyone help me with this?

This is the code which i have typed

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
        backgroundGradientColors="[0xFFFFFF,0xAAAAAA]" horizontalAlign="left" 
        horizontalGap="15" verticalGap="15" width="459" height="371">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            public var photoBindable:ArrayCollection;
            private function requestPhotos():void{
                photoService.cancel();
                var params:Object=new Object();
                params.format = 'rss_200_enc';
                params.tags = searchTerm.text;
                photoService.send(params);
            }
            private function photoHandler(event:ResultEvent):void{
                photoBindable=event.result.rss.channel.items as ArrayCollection;
            }
        ]]>
    </mx:Script>
    <mx:HTTPService id="photoService"
        url="http://api.flickr.com/services/feeds/photos_public.gne"
        result="photoHandler(event)" />
    <mx:HBox>
        <mx:Label text="Flicker tags" />
        <mx:TextInput id="searchTerm" />
        <mx:Button label="Search" click="requestPho开发者_如何学编程tos()"/>
    </mx:HBox>
    <mx:TileList width="100%" height="100%"
        dataProvider="{photoBindable}"
        itemRenderer="thumbnail">
    </mx:TileList>
</mx:Application>

This is itemRender thumbnail.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="75" height="75"
        horizontalScrollPolicy="off" verticalScrollPolicy="off"
        paddingBottom="5" paddingLeft="5" paddingTop="5">
    <mx:Image width="75" height="75" source="{data.thumbnail.url}" />
    <mx:Text text="{data.credits}" />
</mx:VBox>


Of course there's an error in the XML or in the .php file, maybe blank space or something else; check the first line of xml which has to start only with the following statement:

<?xml version="1.0" encoding="utf-8"?>

I'm quite sure you forget to import the itemRender:

<mx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.rpc.events.ResultEvent;
        import itemRender; //substitute itemRender with your own itemRender.mxml file
    ]]>
</mx:Script>

Anyway take a look to this page even if it's italian language the code is very simple to understand.

Hope to be useful


I think the problem is in this tag event.result.rss.channel.items it is not items it is item Remove the extra 's' ..... The example is good...it worked for me...you can use this code below to check

Printing my code here...i added some more stuff to it

FlickrPrj.mxml

    <mx:Script>
        <![CDATA[
            import mx.events.ListEvent;
            import mx.controls.Alert;
            import mx.managers.PopUpManager;
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;

           [Bindable]
           public var photoFeed:ArrayCollection;

            public function searchFlickr():void {
                photoService.cancel();
                var params:Object = new Object();
                    params.format = 'rss_200_enc';
                    params.tags = srchTxtId.text;               
                photoService.send(params);
            }

            public function resultHandler(event:ResultEvent):void {
                photoFeed = event.result.rss.channel.item as ArrayCollection;
            }

            public function openPanel(levent:ListEvent):void {
                var panelCmpObj:panelcomp = new panelcomp();    
                   panelCmpObj.source = levent.itemRenderer.data.content.url;           
                PopUpManager.addPopUp(panelCmpObj,this,true);
            }
            public function test():void {
                Alert.show('testtest');
                }           

        ]]>
    </mx:Script>

    <mx:HTTPService id="photoService" url="http://api.flickr.com/services/feeds/photos_public.gne" result="resultHandler(event)"/>

    <mx:HBox width="362" height="24">
        <mx:TextInput id="srchTxtId"/>
        <mx:Button label="Search for pics" id="srchBtnId" click="searchFlickr()"/>
    </mx:HBox>
    <mx:TileList id="imgTileList" dataProvider="{photoFeed}" width="100%" height="100%" itemClick="openPanel(event)">   
    <mx:itemRenderer>
        <mx:Component>
          <mx:VBox width="125" height="125"
                paddingBottom="5"
                paddingLeft="5"
                paddingTop="5"
                paddingRight="5">
                <mx:Image width="75" height="75" source="{data.thumbnail.url}"/>
          </mx:VBox>
        </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>

</mx:Application>

panelcomp.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
        showCloseButton="true"
        styleName="noPadding"
        creationComplete="init();"
        close="titleWindow_close(event);">
<mx:Script>
        <![CDATA[
            import mx.managers.IFocusManagerComponent;
            import mx.controls.Alert;
            import mx.core.IFlexDisplayObject;
            import mx.events.CloseEvent;
            import mx.managers.PopUpManager;

            [Bindable]
            public var source:String;

            private function init():void {
                PopUpManager.centerPopUp(this);
            }

            private function titleWindow_close(evt:CloseEvent):void {
                PopUpManager.removePopUp(evt.target as IFlexDisplayObject);
            }
        ]]>
    </mx:Script>

    <mx:Image width="379" height="261" id="imgId" source="{source}"/>
       <mx:ControlBar horizontalAlign="right" width="100%">
    </mx:ControlBar>

</mx:TitleWindow>

Note put FlickPrj.mxml and panelcomp.mxml in the same directory.


It means that the xml file that was loaded was not written properly , try to open it in IE ( or some xml tool such as altova ) and see whats wrong with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号