views:

736

answers:

2

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

+1  A: 

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"/&gt;
</mx:Application>

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

dirkgently
I tried this code and was able to export my project finally. Only thing is, I still don't see anything in my data table...
LaBopeep
Are you able to hit any breakpoint?
dirkgently
By breakpoint, you mean I should see an error displayed on my html page? The table is still showing with nothing displayed as it was before.
LaBopeep
No. You insert a breakpoint on a line and when you run the program in debug mode (using F11) the program will come to that step and pause there until you ask it move forward (F6 or F8) i.e. if you are using Flex Builder.
dirkgently
Can you compile your program without any errors?
dirkgently
I finally used the F11 mode and received several errors in the browser.
LaBopeep
Great! So you can compile without any error? What you are getting (a crash) is a runtime error. What does it look like (the first 4 lines at least?) Put it in your question and we'll see.
dirkgently
The first few lines have been edited in the question now.
LaBopeep
Hmm, I will have to try something else. My php file is definitely set to an array value and even setting the resultFormat=array or just using the default object, I still receive the same error.
LaBopeep
Try returning an Array from your PHP file.
dirkgently
My php file does return an array from the database. http://www.keishalexie.com/imd465/forum.php?getTutorials=1
LaBopeep
This is JSON data. You will have to use ascorelib's JSON serialization module IMO.
dirkgently
Yes, I have the library installed. I guess it's not working right. Thanks for all your help! :-)
LaBopeep
Or, change the data returned by your PHP script. For all the field identifiers like id, instead of "id":"something" make it id:"something" and it'll be a valid object then.
dirkgently
I have id="getData" in the mxml and no such luck. Argh, I give up at this point.
LaBopeep
No, change the way the PHP script formats the result.
dirkgently
A: 

I have an Parse error at ''. error. Pls help reply at [email protected] Thanks

import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.controls.Alert; import mx.rpc.http.HTTPService; import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; import mx.effects.Resize;

 [Bindable]
 private var sites:ArrayCollection = new ArrayCollection();
 [Bindable]
 public var myURL:String; 

 private function siteListHandler(event:ResultEvent):void{
  sites = event.result.sites.site;
  var siteObj:Object = new Object();
  siteObj.name = "Select"
  siteObj.url = "";
  sites.addItemAt(siteObj,0);
  siteCombo.selectedIndex = 0;
   //trace(event.result);
  }

  public function chooseSiteFeed(url:String, name:String):void{
   myURL = url;
     mdFeed.send();
  }

</mx:Script>