R – Parse Error When Trying to Set a Break in Flex 3

actionscriptapache-flexhttp

I have been trying unsuccessfully to set a HTTP break in my Flex 3 project. Obviously, I am totally clueless about programming and I don't have many references. When I try to export the project I receive parse errors for the result handler and var fault string. I am attaching a code snippet of where I have been placing the break.

<mx:HTTPService id="getData" url="http://www.myurl.com"


useProxy="false" method="GET" resultFormat="text" resultType="text" 
         result="resultHandler(event)" fault="faultHandler(event)">

private function resultHandler(e:ResultEvent):void {
        trace(e.result); 
}


private function resultHandler(e:FaultEvent):void {
        var faultstring:String = event.fault.faultString; 
        Alert.show(faultstring); 
}


<mx:request xmlns="">
  <getTutorials>"true"</getTutorials>


</mx:request>

I think this may have to do with the PHP file and the type of data the Flex is looking for? Here is the first bit of the error I am receiving in the browser.

TypeError: Error #1034: Type Coercion failed: cannot convert "[{"id":"2","name":"Strapless Wedding Dress Tips","author":"Ramona Waters","rating":"0"},{"id":"3","name":"Coordinating Your Brides Maids","author":"Ericka Brown","rating":"0"}]" to mx.controls.Alert.
at DressBuilder2/resultHandler()
at DressBuilder2/__getData_result()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()

Best Answer

Update: Cool, you've got your code compiled! Try with the following:

  • Set resultFormat=array if you have an array of objects. Get this value in an array and loop over to see if you have can see the items. If this doesn't work try next tip.
  • Remove the resultFormat from the HTTPService tag (which is the same as if you had set it to object). See this.

The functions in AS typically go inside a <mx:Script> tag. That's the first thing to fix. You will also have to import the definitions of the classes you are using. Have a look here:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute" width="535" height="345"
                creationComplete="getData.send()">
<mx:Script>
  <![CDATA[
 import mx.rpc.events.FaultEvent;
 import mx.rpc.events.ResultEvent;
 import mx.controls.Alert;
     import mx.rpc.http.HTTPService;

 private function resultHandler(e:ResultEvent):void {
    Alert(e.result.toString());
 }
 private function faultHandler(e:FaultEvent):void {
    Alert(e.fault.toString());
 }
  ]]>
 </mx:Script>
<mx:HTTPService id="getData" resultFormat="text" 
                fault="faultHandler(event)" result="resultHandler(event)"   
                url="http://www.myurl.com"/>
</mx:Application>

Try using this MXML file and let us know how far you got.

Related Topic